FizzBuzz
JavaScript
Easy
Objective
Write a function that loops through the numbers 1-100.
For multiples of 3, print 'Fizz'
For multiples of 5, print 'Buzz'
For multiples of both 3 & 5, print 'FizzBuzz'
For everything else, print the number
Requirements
The function should be called
fizzbuzz
The function takes no parameters
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