Created
June 15, 2018 06:45
-
-
Save MikSDigital/2759d0de01385df3131999e6d1ea843f to your computer and use it in GitHub Desktop.
js implementation of fizzBuzz algorythm
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 for loop that will iterate through 100 numbers starting from 1 and do the following: | |
if the number is a multiple of 3, it will console.log "fizz", | |
if the number is a multiple of 5, it will console.log "buzz", | |
if the number is a multiple of 3 and 5, it will console.log "fizzBuzz" | |
*/ | |
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment