Last active
January 3, 2018 08:31
-
-
Save eldyvoon/b1ea84d054c1031d467e4948d569bfcf to your computer and use it in GitHub Desktop.
FizzBuzz in JavaScript
This file contains 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
//specs | |
fizzBuzz(15); | |
1 | |
2 | |
fizz | |
4 | |
buzz | |
fizz | |
7 | |
8 | |
fizz | |
buzz | |
11 | |
fizz | |
13 | |
14 | |
fizzbuzz | |
//solution | |
function fizzBuzz(n) { | |
for (let i = 1; i <= n; i++) { | |
if (i % 3 === 0) { | |
console.log('fizz') | |
} else if (i % 5 === 0) { | |
console.log('buzz') | |
} else if (i % 3 === 0 && i % 5 === 0) { | |
console.log('fizzbuzz') | |
} else { | |
console.log(i) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment