Skip to content

Instantly share code, notes, and snippets.

@drmmr763
Created May 16, 2015 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drmmr763/1cf6cd7074ae51dfe112 to your computer and use it in GitHub Desktop.
Save drmmr763/1cf6cd7074ae51dfe112 to your computer and use it in GitHub Desktop.
FizzBuzz
<?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