javascript example

FizzBuzz in JavaScript

Print 1 to 20, replacing multiples of 3 with Fizz, 5 with Buzz, and both with FizzBuzz. Run it online with no signup.

FizzBuzz is a classic loop-and-remainder exercise. For each number, check 15 first so multiples of both 3 and 5 print FizzBuzz instead of only one word.

Use console.log so Code Arena shows each line in Output. Change the range or the words, then Run again.

for (let n = 1; n <= 20; n++) {
  if (n % 15 === 0) console.log("FizzBuzz");
  else if (n % 3 === 0) console.log("Fizz");
  else if (n % 5 === 0) console.log("Buzz");
  else console.log(n);
}