โ† 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.