Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Solution to FizzBuzz problem
/**
* 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" )
);
}
@n0wak

This comment has been minimized.

Copy link

n0wak commented Nov 26, 2012

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]
);
}

@lucasrizoli

This comment has been minimized.

Copy link
Owner Author

lucasrizoli commented Nov 30, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.