38/361

Create a for loop that iterates up to 100 while outputting **"fizz"** at multiples of 3, **"buzz"** at multiples of 5 and **"fizzbuzz"** at multiples of 3 and 5.

Quiz · JavaScript
Medium
3 min
javascript

Check out this version of FizzBuzz by Paul Irish.

for (let i = 1; i <= 100; i++) {
  let f = i % 3 == 0,
    b = i % 5 == 0;
  console.log(f ? (b ? 'FizzBuzz' : 'Fizz') : b ? 'Buzz' : i);
}

I would not advise you to write the above during interviews though. Just stick with the long but clear approach. For more wacky versions of FizzBuzz, check out the reference link below.

Adapted from the Front End Interview Handbook by Yangshun Tay and contributors (MIT License). Source

Spotted a mistake or a rights concern? Report an issue