Created
October 8, 2016 15:31
-
-
Save andersr/2cb1ca9216bc9fa8babd347ebe5b193f to your computer and use it in GitHub Desktop.
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
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