Created
April 14, 2023 21:37
-
-
Save Pinjasaur/1f69d138410c8cb4c9482de9180ddd14 to your computer and use it in GitHub Desktop.
fizzy buzzers
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
/** | |
* Implement the "FizzBuzz" paradigm: iterate 'from' to 'to' inclusive | |
* printing "Fizz" for multiples of 3, "Buzz" for multiples of 5, and | |
* "FizzBuzz" for multiples of both. Otherwise, print the number. | |
* @param {number} from - lower bound, inclusive | |
* @param {number} to - upper bound, inclusive | |
* @return void (undefined) | |
* | |
* @example | |
* | |
* fizzbuzz(1, 100) // 1 through 100 | |
*/ | |
const fizzbuzz = (from, to) => { | |
for (let i = from; i <= to; i++) { | |
if (i % 3 === 0 && i % 5 === 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(1, 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment