Skip to content

Instantly share code, notes, and snippets.

@geraldyeo
Created November 30, 2012 03:30
Show Gist options
  • Select an option

  • Save geraldyeo/4173605 to your computer and use it in GitHub Desktop.

Select an option

Save geraldyeo/4173605 to your computer and use it in GitHub Desktop.
Fizz-Buzz
/*
Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number
and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
*/
var fizzbuzz = function(){
var x = 0, print;
while (++x<=100) {
print = '';
if (x%3==0) {
print = 'Fizz';
}
if (x%5==0) {
print += 'Buzz'
}
console.log(print || x);
}
};
fizzbuzz();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment