Created
May 16, 2015 20:35
-
-
Save drmmr763/1cf6cd7074ae51dfe112 to your computer and use it in GitHub Desktop.
FizzBuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Author: Chad Windnagle | |
* @drmmr763 | |
*/ | |
class FizzBuzz { | |
public $count; | |
public function __construct() | |
{ | |
// init count to our starting number | |
$this->count = 1; | |
} | |
/* | |
** Determines if the number is perfectly divisble by three. | |
** | |
** @param $number int | |
** @return boolean | |
*/ | |
public function isDivisibleByThree($number) | |
{ | |
if ($number % 3 === 0) | |
{ | |
return true; | |
} | |
return false; | |
} | |
/* | |
** Determines if the number is perfectly divisble by five. | |
** | |
** @param $number int | |
** @return boolean | |
*/ | |
public function isDivisibleByFive($number) | |
{ | |
if ($number % 5 === 0) | |
{ | |
return true; | |
} | |
return false; | |
} | |
/* | |
** Execute the counter | |
*/ | |
public function main() | |
{ | |
for($this->count; $this->count <= 100; $this->count++) | |
{ | |
if ($this->isDivisibleByThree($this->count)) | |
{ | |
echo 'Fizz'; | |
} | |
if ($this->isDivisibleByFive($this->count)) | |
{ | |
echo 'Buzz'; | |
} | |
if (! $this->isDivisibleByThree($this->count) && ! $this->isDivisibleByFive($this->count)) | |
{ | |
echo $this->count; | |
} | |
echo '<br />'; | |
} | |
} | |
} | |
$fizzBuzz = new FizzBuzz(); | |
$fizzBuzz->main(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment