Math Fundamentals18 sections · 814 units
Open in Course

Fizz Buzz - Insight

Checking divisibility

A number is divisible by 33 if i mod 3=0i \bmod 3 = 0. A number is divisible by 55 if i mod 5=0i \bmod 5 = 0. Both conditions use modulo to check divisibility.

The tricky part is the order of checks. You must check divisibility by both 33 and 55 first. If you check 33 first and return "Fizz", you never get to check 55.

For i=15i = 15, both 15 mod 3=015 \bmod 3 = 0 and 15 mod 5=015 \bmod 5 = 0 are true, so you output "FizzBuzz".