JavaScript: FizzBuzz question

Last update: 13 Sep 23:24
6
Students

fizzBuzz.js

Write and export as default a function that prints (console.log) numbers from begin to end. But:

  • 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 accepts 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.

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
1000
exercises
2000+
hours of theory
3200
tests