Fizz Buzz program in JavaScript

Last updated:14th Aug 2022

In this article, we will do the FizzBuzz program, it is a basic programming exercise commonly asked in a job interview.

What is FizzBuzz?

FizzBuzz is a task in which the programmer asks to print numbers from 1 to 100, but there are some conditions, when a number is a multiple of three then print fizz, similarly for a multiple of five print Buzz, and for multiple of three and five print FizzBuzz.


for (var i = 1; i <= 100; 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);
}

output

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
..
...
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz
Buzz