Skip to content

Instantly share code, notes, and snippets.

@lucasrizoli
Created November 15, 2012 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasrizoli/4079640 to your computer and use it in GitHub Desktop.
Save lucasrizoli/4079640 to your computer and use it in GitHub Desktop.
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" )
);
}
@lucasrizoli
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment