Fizzbuzz – My Way


I’ve known about the Fizzbuzz test for a while, but this post recently reminded me of it.

For those that don’t know it, it’s a basic test of logic (based on a children’s maths game) where you need to print out the numbers from 1 to 100. ¬†When a number is divisible by 3, instead of writing “3” you write “fizz”. Similarly, when a number is¬†divisible by 5 you write “buzz”. Lastly, where the number is divisible by 3 and 5 at the same time, you write “fizzbuzz”.

There are a lot of ways to do this the right way (and even more ways to do this incorrectly) – which makes it a great test for potential programmers.

My take on this adds a couple of variables, and allows the test to be performed using any two numbers (not just 3 and 5).

The result looks like this:




Leave a Reply

Your email address will not be published. Required fields are marked *