FizzBuzz

Home page

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz"

Try out my solution below.

Iterative:
FizzBuzz = () => {
    for (let i = 1; i <= 100; i++) {
        if (i % 15 === 0)
            console.log('FizzBuzz');
        else if (i % 3 === 0)
            console.log('Fizz');
        else if (i % 5 === 0)
            console.log('Buzz');
        else
            console.log(i);
    }
}
Iterative:
FizzBuzz = (n) => {
    if (n % 15 === 0)
        result.push('FizzBuzz');
    else if (n % 3 === 0)
        result.push('Fizz');
    else if (n % 5 === 0)
        result.push('Buzz');
    else
        result.push(n);
    if (n < 100)
        FizzBuzz(n+1);
}
Shortest
FizzBuzz = () => {
    for(let i=0;i<100;)result.push((++i%3?'':'fizz')+(i%5?'':'buzz')||i)
}
Answer: