Last active
December 6, 2016 20:54
-
-
Save armenr/b91cfa7924864822fa000d585d8e8972 to your computer and use it in GitHub Desktop.
fizzBuzz.js
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
// My Code | |
for (var i = 1; i <= 100; i++) { | |
switch (true) { | |
//case ((i % 3 === 0) && (i % 5 === 0)): | |
case (i % 15 === 0): // Use one comparison instead of two, because maths | |
console.log("FizzBuzz"); | |
break; | |
case (i % 3 === 0): | |
console.log("Fizz"); | |
break; | |
case (i % 5 === 0): | |
console.log("Buzz"); | |
break; | |
default: | |
console.log(i); | |
} | |
} |
yup LGTM. The switch
idea is just as good as using a bunch of if/else
conditionals. In fact while it might look a bit weird upon first pass, it's probably going to be a little cleaner
Thanks @erikyuzwa!
There, I fixed it for you: https://jsfiddle.net/dhallman/8kpy0mr9/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
no biggie - missing trailing
;