Skip to content

Instantly share code, notes, and snippets.

@gojun077
Created September 13, 2012 13:43
Show Gist options
  • Save gojun077/3714376 to your computer and use it in GitHub Desktop.
Save gojun077/3714376 to your computer and use it in GitHub Desktop.
CodeAcademy - Review Primitives in JS, Sec 4/7, Ex 2/3
/*
2. FizzBuzz Revisited
Now that we know more about Boolean operations, let's return to the
FizzBuzz exercise and explore it a bit more.
We've given you the output we want in console.log(""). All you have
to do is provide the code for the conditions that will result in the
correct Boolean value for each if statement.
Place the right conditions in the right places. Use Boolean operations
where needed.
*/
// for the numbers 1 through 20,
for ( i=1; i<=20; i++) {
// if the number is divisible by 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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment