~/workshop
CODING CHALLENGE · N°03
Fizz Buzz
Easy
MathStringsWarm-up
The famous screening question. Print 1…n, but multiples of 3 become "Fizz", of 5 become "Buzz", and of both become "FizzBuzz". Easy — the catch is testing divisibility in the right order.
The problem
Return a list of length n where, for each i from 1 to n: it is "FizzBuzz" if i is divisible by both 3 and 5, "Fizz" if only by 3, "Buzz" if only by 5, otherwise the number as a string.
EXAMPLE 1
Input
n = 5Output
["1", "2", "Fizz", "4", "Buzz"]
EXAMPLE 2
Input
n = 15Output
[..., "13", "14", "FizzBuzz"]15 is divisible by 3 and 5
EXAMPLE 3
Input
n = 3Output
["1", "2", "Fizz"]
CONSTRAINTS
- 1 ≤ n ≤ 10⁴
- Every element is a string — including the plain numbers.
- Check divisibility by 15 first (or combine the two booleans), or the FizzBuzz case never fires.
Your turn — write it
Edit the stub, hit Run (or ⌘/Ctrl + Enter), and watch the hidden tests. Stuck? the hints are right above and Reveal solution is one click away.
YOUR TASK
Implement fizzbuzz(n): return the list of length n following the Fizz / Buzz / FizzBuzz rules. Watch the order — test "both" before either single case.
HINTS — 4 IDEAS
- Loop
ifrom 1 to n inclusive. - Divisible by both 3 and 5 is the same as divisible by 15 — check that first.
- Otherwise check 3, then 5, then fall back to the number.
- Everything in the list is a string, so convert the plain numbers too.
1
1