This morning someone on twitter (@brooklynDev) commented about how good the FizzBuzz test was to weed out bad programmers. I’ve been interviewing for a few jobs recently and by co-incidence so I wanted to give it a go.

In essence it is as follows:

"Write a program that prints the numbers from 1 to 100.
But for  multiples of three print “Fizz” instead of the number and for the  multiples of five print “Buzz”.
For numbers which are multiples of both  three and five print “FizzBuzz?”."

Pretty straight forward right? I thought so anyway… Here’s my solution. It took about 5 minu

$i = 1;
while($i <= 100) {  
$divThree = (($i % 3) > 0) ? false : true;
$divFive = (($i % 5) > 0) ? false : true;

if($divThree) echo 'Fizz';
if($divFive) echo 'Buzz';

if(!$divThree && !$divFive) echo $i;

echo '';

$i++;
}

I saw another solition which involved the use of a case statement with a “true” test condition which I also liked, but it is not something which immediately jumped to mind for me.