Skip to content

Instantly share code, notes, and snippets.

@armenr
Last active December 6, 2016 20:54
Show Gist options
  • Save armenr/b91cfa7924864822fa000d585d8e8972 to your computer and use it in GitHub Desktop.
Save armenr/b91cfa7924864822fa000d585d8e8972 to your computer and use it in GitHub Desktop.
fizzBuzz.js
// 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);
}
}
@erikyuzwa
Copy link

no biggie - missing trailing ;

@erikyuzwa
Copy link

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

@armenr
Copy link
Author

armenr commented Dec 6, 2016

Thanks @erikyuzwa!

@davehallman
Copy link

davehallman commented Dec 6, 2016

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