Rates TodayNIFTY25,670-0.83%SENSEX83,630.7-0.83%Gold 24K ₹11,320.24/g down186.46Silver ₹134.77/g down2.72
InsightforGeeks

FizzBuzz

EasyLoops · JavaScript

The task

Write fizzBuzz(n) that returns an array of strings for the numbers 1 to n.

For multiples of 3 use "Fizz", for multiples of 5 use "Buzz", and for multiples of both use "FizzBuzz". Otherwise use the number as a string.

Examples

  • fizzBuzz(5) returns ["1","2","Fizz","4","Buzz"]

Your code runs in your browser, in a separate worker, and is never sent to us. Edit the function, then press Run tests. Your work is saved here as you type.

JavaScript

Stuck?