Created
July 6, 2024 14:22
-
-
Save danywalls/6f8db1e3682f35194640460ab99c2b8b to your computer and use it in GitHub Desktop.
fizz-buzz
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 generateNumbers(from: number, to: number) | |
{ | |
for(let index = from; index <= to; index++) { | |
const message = getMessage(index) | |
console.log(message) | |
} | |
} | |
function getMessage(num: number): string{ | |
const isFizz = num % 3 === 0; | |
const isBuzz = num % 5 === 0; | |
let message = num.toString(); | |
if(isFizz) { | |
message = 'fizz'; | |
} | |
if(isBuzz) { | |
message = 'buzz' | |
} | |
if(isFizz && isBuzz){ | |
message = 'fizzbuzz' | |
} | |
return message; | |
} | |
generateNumbers(1,100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment