Last active
July 12, 2023 07:31
-
-
Save mtzfox/437e6f94befa6e0b30b1405998274b8c to your computer and use it in GitHub Desktop.
The classic
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
function fizzBuzz(n) { | |
for (let i = 1; i <= n; i++) { | |
if (i % 15 === 0) return 'FizzBuzz' | |
if (i % 5 === 0) return 'Buzz' | |
if (i % 3 === 0) return 'Fizz' | |
else { | |
return i | |
} | |
} | |
} |
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
function fizzbuzz(n) { | |
const results = [] | |
for (let i = 1; i <= n; i++) { | |
if (i % 15 === 0) results.push('FizzBuzz') | |
else if (i % 3 === 0) results.push('Fizz') | |
else if (i % 5 === 0) results.push('Buzz') | |
else { | |
results.push(i) | |
} | |
} | |
return results | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment