FizzBuzz

JavaScript
Easy

Objective

Write a function that loops through the numbers 1-100.

  1. For multiples of 3, print 'Fizz'

  2. For multiples of 5, print 'Buzz'

  3. For multiples of both 3 & 5, print 'FizzBuzz'

  4. For everything else, print the number

Requirements

  1. The function should be called fizzbuzz

  2. The function takes no parameters

  3. You can either return the values as an array or log them to the console

Solution

Here's how I would approach this, but keep in mind there might be other ways to solve this problem.

function 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); } } }
Click to reveal