Last active
August 29, 2015 14:00
-
-
Save oddurs/11329726 to your computer and use it in GitHub Desktop.
FizzBuzz (CodeAcademy)
This file contains hidden or 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
/* | |
FizzBuzz / Javascript exercise | |
As instructed by CodeAcademy | |
Oddur Sigurdsson | |
26. april 2014 | |
*/ | |
// (starting variable, condition, execute each time) | |
for (i = 1; i <= 100; i++) { | |
// if i has no remainder when divided by 15 (or 3 AND 5) | |
if (i % 15 == 0){ | |
console.log("FizzBuzz") | |
} | |
else { | |
// if i has no remainder when divided by 3 | |
if (i % 3 == 0) { | |
console.log("Fizz") | |
} | |
// else if i has no remainder when divided by 5 | |
else if (i % 5 == 0){ | |
console.log("Buzz") | |
} | |
// otherwise just print i | |
else { | |
console.log(i) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment