Skip to content

Instantly share code, notes, and snippets.

@danywalls
Created July 6, 2024 14:22
Show Gist options
  • Save danywalls/6f8db1e3682f35194640460ab99c2b8b to your computer and use it in GitHub Desktop.
Save danywalls/6f8db1e3682f35194640460ab99c2b8b to your computer and use it in GitHub Desktop.
fizz-buzz
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