Skip to content

Instantly share code, notes, and snippets.

@johanbove
Last active August 29, 2015 14:24
Show Gist options
  • Save johanbove/120191a5c6912359dc6e to your computer and use it in GitHub Desktop.
Save johanbove/120191a5c6912359dc6e to your computer and use it in GitHub Desktop.
Fizzbuzz
// Inspired by http://c2.com/cgi/wiki?FizzBuzzTest
/*
"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 i;
for (i = 0;i <= 100; i++) {
var test = "";
test += (i % 3) == 0 ? "fizz" : "";
test += (i % 5) == 0 ? "buzz" : "";
console.info(i, (test.length) ? test : i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment