Practice

FizzBuzz

MEDIUMLoops

Read a positive integer N. For each number from 1 to N, output:

  • FizzBuzz if divisible by both 3 and 5
  • Fizz if divisible by 3 only
  • Buzz if divisible by 5 only
  • The number itself otherwise

Input: A positive integer N. Output: N lines, one per number.

Example (N = 5):

1
2
Fizz
4
Buzz

Sample Test Cases

Test 1: First 5
Inputs: 5
Expected: 1 2 Fizz 4 Buzz
Test 2: First 15 (includes FizzBuzz)
Inputs: 15
Expected: 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz

Premium Question

This question needs a paid plan — upgrade, or join a class from a teacher who has one. You can read the description and sample tests, but grading is locked.

Sign in to get started