← JavaScript
#9 most askedVery commonEasyArrays & objects

FizzBuzz

🏒 Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

Write fizzBuzz(n) that returns an array of strings for the numbers 1 to n: multiples of 3 β†’ "Fizz", multiples of 5 β†’ "Buzz", multiples of both β†’ "FizzBuzz", otherwise the number as a string.

fizzBuzz(5) β†’ ["1", "2", "Fizz", "4", "Buzz"]

πŸ§ͺ Practice

Write your solution, then press Run tests. Explain your approach out loud as you go.

JavaScript
function fizzBuzz(n) {
  // your code here
}

Output appears here. Press Run or Ctrl/⌘ + Enter.

Try it first. Struggling for a few minutes is how it sticks.