Skip to content

Instantly share code, notes, and snippets.

@oddurs
Last active August 29, 2015 14:00
Show Gist options
  • Save oddurs/11329726 to your computer and use it in GitHub Desktop.
Save oddurs/11329726 to your computer and use it in GitHub Desktop.
FizzBuzz (CodeAcademy)
/*
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