Skip to content

Instantly share code, notes, and snippets.

@albertodeago
Last active February 11, 2019 19:32
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 albertodeago/2b57dbd0a0f22d6be27cc36488cb957f to your computer and use it in GitHub Desktop.
Save albertodeago/2b57dbd0a0f22d6be27cc36488cb957f to your computer and use it in GitHub Desktop.
Simple JS implementation of the fizzbuzz problem
/**
* 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”.
*/
function fizzBuzz(num) {
var i = 0;
while(i <= num) {
var output = "";
if(Number.isInteger(i / 3)) {
output += "fizz"
}
if(Number.isInteger(i / 5)) {
output += "buzz"
}
output = output ? output : i;
console.log(output);
++i;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment