Created
November 15, 2012 16:42
-
-
Save lucasrizoli/4079640 to your computer and use it in GitHub Desktop.
Solution to FizzBuzz problem
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
/** | |
* Inspired by http://www.globalnerdy.com/2012/11/15/fizzbuzz-still-works/ | |
* | |
* Write a program that prints the numbers from 1 to 100, but | |
* for multiples of 3 print "Fizz" instead of the number and | |
* for the multiples of 5 print "Buzz." For numbers which are | |
* multiples of both 3 and 5 print "FizzBuzz." | |
*/ | |
for( var i = 1; i <= 100; i += 1 ) { | |
console.log( | |
( i % 3 ) ? ( ( i % 5 ) ? i : "Buzz" ) : ( ( i % 5 ) ? "Fizz" : "FizzBuzz" ) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var i = 0, b = ["","Buzz","Fizz"];
while (i++ < 100) {
console.log(
(i % 3 && i % 5) ? i: b[i%5?0:2] + b[i%3?0:1]
);
}