Skip to content

Instantly share code, notes, and snippets.

@andersr
Created October 8, 2016 15:31
Show Gist options
  • Save andersr/2cb1ca9216bc9fa8babd347ebe5b193f to your computer and use it in GitHub Desktop.
Save andersr/2cb1ca9216bc9fa8babd347ebe5b193f to your computer and use it in GitHub Desktop.
for (var i = 1; i <= 100; i++) {
if (i % 3 === 0 && i % 5 === 0) {
console.log('fizzbuzz')
} else if (i % 3 === 0) {
console.log('fizz')
} else if (i % 5 === 0) {
console.log('buzz')
}
}
// One would think that using switch would be better, since we have multiple if-elses, but it's actually not shorter, and in fact less clear, imo
// for (var i = 1; i <= 100; i++) {
// switch(true) {
// case (i % 3 === 0 && i % 5 === 0):
// console.log('fizzbuzz')
// break
// case (i % 5 === 0):
// console.log'buzz')
// break
// case (i % 3 === 0):
// console.log('fizz')
// }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment