Last active
February 11, 2019 19:32
-
-
Save albertodeago/2b57dbd0a0f22d6be27cc36488cb957f to your computer and use it in GitHub Desktop.
Simple JS implementation of the fizzbuzz problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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