Last active
June 16, 2018 21:02
-
-
Save rodrigolira/a8935f2905d5004fec679e2b147984f5 to your computer and use it in GitHub Desktop.
Implementing the FizzBuzz algorithm in Javascript
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
// Create a funcion that will receive an integer number as a parameter and output to the log every number from 1 to the parameter. | |
// For each number divisible by 3, it should log the word "Fizz" instead of the number. | |
// For each number divisible by 5, it should log the word "Buzz" instead of the number. | |
// For each number divisible by 3 and 5, it should log the word "FizzBuzz" instead of the number. | |
function fizzBuzz(num) { | |
for (var i = 1; i <= num; i++) { | |
if (i % 15 == 0) console.log("FizzBuzz") | |
else if (i % 3 == 0) console.log("Fizz") | |
else if (i % 5 == 0) console.log("Buzz") | |
else console.log(i); | |
} | |
} | |
fizzBuzz(45); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment