My First PHP Kata – FizzBuzz

  Jason wrote this on Jun 24 2013 / 0 comments




So I recently read the clean coder. Very interesting book. I am not sure how much of that book I want to practice or if I believe any of it is relavent to me yet. Ill post later on a more definitive decision on it.

A kata is a simple exercise to strengthen your ability or knowledge of code. Something you can do every morning or whenever you have time for a quick 5 minute exercise.

However I do find the idea of practicing simple code to be rather awesome. So I did some research and found this one. Its called FizzBuzz. A rather simle excersice to echo out different words based on which number. So here is what I came up with as my first test.

<?php
    //FizzBuzz in PHP

    //Directions: 
        // Print 1 to 100
        // Multiples of 3 print Fizz
        // Multiples of 5 print Buzz
        // MUltiples of both print FizzBuzz
        // http://www.codingdojo.org/cgi-bin/wiki.pl?KataFizzBuzz

        for ( $i = 0; $i <=100; $i++) {

            if( 0 == $i % 3 && 0 == $i % 5 ) {

                echo "FizzBuzz \n";

            }elseif( 0 == $i % 3 ) {

                echo "Fizz \n";

            }elseif( 0 == $i % 5 ) {

                echo "Buzz \n";

            }else{

                echo $i."\n";

            }

        }
?>

I think im going to start trying to regularly practice. I’m definitely out of touch with my programming abilities. Time to up my game yo!

This piece is tagged in...

Drop a Note