Print out the numbers from 1 - 20.
The rules:
For numbers divisible by 3, print out "Fizz".
For numbers divisible by 5, print out "Buzz".
For numbers divisible by both 3 and 5, print out "FizzBuzz" in the console.
Otherwise, just print out the number.
for (var i = 1; i <= 20; i++) {
if (i % 3 === 0 && i % 5 != 0) {
console.log("Fizz");
} else if (i % 5 === 0 && i % 3 != 0) {
console.log("Buzz");
} else if (i % 5 === 0 && i % 3 === 0) { console.log("FizzBuzz");
} else {
console.log(i);
}
}
for(var i = 0;i<20;i++) {
var str = '';
if (i % 3 === 0) {
str += 'Fizz';
}
if (i % 5 === 0) {
str += 'Buzz';
}
console.log(str ? str : i);
}
var range = Array.apply(0, Array(20)).map(function(n , i) { return i; });
if (b3){
if (b5) {
console.log("FizzBuzz");
} else {
console.log("Fizz");
}
} else if (b5) {
console.log("Buzz");
} else {
console.log(i);
}
for( var i = 1, div_3 = false, div_5 = false; i <= 20; i++ ) {
div_3 = ( i % 3 == 0 );
div_5 = ( i % 5 == 0 );
if ( div_3 && div_5 ) {
console.log( "FizzBuzz" );
}
else if ( div_3 ) {
console.log("Fizz");
}
else if ( div_5 ) {
console.log("Buzz");
}
else {
console.log(i);
}
}