Print integers one through
n
, but print ‘Fizz’ if an integer is divisible by three, ‘Buzz’ if an integer is divisible by five, and ‘FizzBuzz’ if an integer is divisible by both three and five.
Solution
This is the answer I came up with:
Since the functionalities for Fizz, Buzz, and FizzBuzz are separate, it makes sense to create individual functions for each condition. I then created the final
fizzBuzz
function using composition, which I think was an elegant solution.