
Untitled
By: a guest on Jan 28th, 2012 | syntax:
None | size: 0.57 KB | hits: 307 | expires: Never
// Add an else statement in case the number is divisible by 5.
// for the numbers 1 through 20,
for (i=1; i<=20; i++) {
// if the number is divisible by both 3 and 5, write "FizzBuzz"
if ( i % 3 === 0 && i % 5 === 0) {
console.log("FizzBuzz");
}
// if the number is divisible by 3, write "Fizz"
else if ( i % 3 === 0 ) {
console.log("Fizz");
}
// if the number is divisible by 5, write "Buzz"
else if (i % 5 === 0 ){
console.log("Buzz");
}
// otherwise, write just the number
else {
console.log(i);
}
}