This website uses cookies to enhance the user experience

FizzBuzz

Difficulty: 🐣 Easy

Problem Statement

Write a program that outputs the string representation of numbers from 1 to n.

But for multiples of three, it should output 'Fizz' instead of the number and for the multiples of five output 'Buzz'. For numbers which are multiples of both three and five output 'FizzBuzz'.

Example
Input: n = 15
Output: ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]
Constraints
  • 1 <= n <= 10^4

Expected Challenge Output

When the function fizzBuzz is called with the given example input, the expected output is:

  • For the input 15, the output is ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"].

console.log(fizzBuzz(15));  // Output: ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]
function fizzBuzz(n) {
// YOUR SOLUTION HERE
}

Memory: 0

CPU: 0