FizzBuzz for Javascript

terrythreatt

Terry Threatt

Posted on July 10, 2021

FizzBuzz for Javascript

New developers will surely see this problem show up in technical interviews. FizzBuzz is a classic technical interview questions to find out if you are familiar with solving programming challenges.

FizzBuzz setup:

Create a solution that prints the number 1 through 100. Print "Fizz" for numbers that have a multiple of 3. Print "Fizz" for numbers that have a multiple of 5. Print "FizzBuzz" for numbers that have a multiple of both 3 and 5.

FizzBuzz solution: (There's many ways to solve this problem)

for (let i = 1; i <= 100; i++) {
    // Finding multiples of 3 and 5
    if (i % 3 === 0 && i % 5 === 0) {
      console.log('FizzBuzz');
    } else if (i % 3 === 0) {
      // Finding multiples of 3
      console.log('Fizz');
    } else if (i % 5 === 0) {
      // Finding multiples of 5
      console.log('Buzz');
    } else {
      console.log(i);
    }
  }
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
terrythreatt
Terry Threatt

Posted on July 10, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Seek and Destroy Algorithm
javascript Seek and Destroy Algorithm

May 12, 2023

FizzBuzz for Javascript
javascript FizzBuzz for Javascript

July 10, 2021