Fizz Buzz is well-known introduction to programming exercises and katas, because it has a simple enough premise that one can learn the approach of the exercises without worrying about the challenge of any code itself.
This kata replicates a simple number game in which you count numbers, but replace some of the numbers with “Fizz”, “Buzz”, or “FizzBuzz” depending on the divisors of the number. For numbers divisible by 3, replace with “Fizz”. For numbers divisible by 5, replace with “Buzz”. For those divisible by both, replace with “FizzBuzz”.
Instructions
- Create a function that prints (each on their own lines) the numbers 1 through 100 with the following exceptions:
- Numbers divisible by 3 should print “Fizz” instead of the number.
- Numbers divisible by 5 should print “Buzz” instead of the number.
- Numbers divisible by 3 and 5 should print “FizzBuzz” instead of the number.
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
Fizz Buzz Extra Credit
Finished the exercise early and want to add a bit more complexity?
- Numbers containing the digit ‘3’ should print “Fizz” instead of the number.
- Numbers containing the digit ‘5’ should print “Buzz” instead of the number.
- Numbers containing the digits ‘3’ and ‘5’ should print “FizzBuzz” instead of the number.