Skip to content

Instantly share code, notes, and snippets.

@MikSDigital
Created June 15, 2018 06:45
Show Gist options
  • Save MikSDigital/2759d0de01385df3131999e6d1ea843f to your computer and use it in GitHub Desktop.
Save MikSDigital/2759d0de01385df3131999e6d1ea843f to your computer and use it in GitHub Desktop.
js implementation of fizzBuzz algorythm
/*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