Javascript: Fizz and Buzz

JavaScript fundamentals
Last update: 14 Jun 13:04
0
Students

fizzBuzz.js

Write and export as default a function that prints (console.log) numbers in a range from the begin to the end. With some conditions:

  • If the number is a multiple of 3, print Fizz instead of the number
  • If the number is a multiple of 5, print Buzz instead of the number
  • If the number is a multiple of both 3 and 5, print FizzBuzz instead of the number
  • Otherwise, print the number

The function takes two parameters (begin and end). They define the range and are inclusive. If the range is empty (when begin > end), the function shouldn't print anything.

Call example:

fizzBuzz(11, 20);

Output:

11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
900
exercises
2000+
hours of theory
3200
tests