Created
February 3, 2023 11:01
-
-
Save CodeLeom/e01c89591c467542b1d786f9feb40b7f to your computer and use it in GitHub Desktop.
This gist is an answer to, write the fizzbuzz javascript algorithm which returns an array of strings from 1 to N but for multiples of 3, print Fizz, multiples of 5, print Buzz, multiples of 3 and 5, print fizz buzz
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
| function fizzbuzz(n) { | |
| let result = []; | |
| for (let i = 1; i <= n; i++) { | |
| let output = ""; | |
| if (i % 3 === 0) { | |
| output += "Fizz"; | |
| } | |
| if (i % 5 === 0) { | |
| output += "Buzz"; | |
| } | |
| if (output === "") { | |
| output += i; | |
| } | |
| result.push(output); | |
| } | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment