← All Exercises

FizzBuzz Classic

basicjavascript~10min

Background

FizzBuzz is the most famous programming screening question, testing basic logic and loop construction skills.

Problem

Write a function that returns an array of strings for numbers 1 to n, where multiples of 3 show Fizz, multiples of 5 show Buzz, and multiples of both show FizzBuzz.

Input

A positive integer n representing the upper bound (inclusive).

Output

An array of strings, each being the number, Fizz, Buzz, or FizzBuzz.

Sample tests

Sample 1

Input: 5
Expected: ["1","2","Fizz","4","Buzz"]

Your solution

Learning objective

Practice conditional logic, loop construction, and modulo operator usage.