Code Kata: Fizz Buzz Game

Posted on Tue 20 December 2011 in Developer • Tagged with code, coding, game, kata, programmer, programmingLeave a comment

I stared to practice recently after reading more about how practicing is important for programmer to become professional and one way of practicing is Coding Kata. I found a lot of problem to implement to practice and perform coding kata.

This post I'll talk about Fizz Buzz Game a.k.a. Bizz Buzz Game, it's numerical/math game, if the number is divisible by 3 replace it with fizz, or if number divisible by 5 replace it with buzz, or if number is divisible by 3 and 5 replace it with fizzbuzz. For example if we count from 1 to 20 it'll be like this: 1, 2, fizz, 4, buzz, fizz, 7, 8, fizz, buzz, 11, fizz, 13, 14, fizzbuzz, 16, 17, fizz, 19, buzz.

So how to code this game:

First I thought I can solve this game by:

If (this number is divisible by 3 and not divisible by 5)  return fizz

else if (this number is not divisible by 3 and divisible by 5)  return buzz

else if (this number is divisible by 3 and divisible by 5)  return buzzfizz

else if(this number is not divisible by 3 and not divisible by 5)  return the number …

Continue reading