Created
January 10, 2012 16:59
-
-
Save madysondesigns/1590013 to your computer and use it in GitHub Desktop.
Codecademy FizzBuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 3, write "Fizz" | |
if ( i % 3 === 0 ) { | |
// if the number is divisible by 3 and 5, write "FizzBuzz" | |
if ( i % 5 === 0 ) { | |
console.log("FizzBuzz"); | |
} | |
else { | |
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
Aha, that was it! I didn't know that you could just continue working with the result of the i % 3 test. I thought you had to find a way to say if i % 3 === 0 AND i % 5 === 0.
Thank you so much!