Last active
August 29, 2015 14:25
-
-
Save dadamssg/d964d2e3748ce3e35393 to your computer and use it in GitHub Desktop.
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 | |
class FizzBuzz | |
{ | |
public function solve($start = 1, $end = 100) | |
{ | |
for($i = $start; $i <= $end; $i++) { | |
$this->print($i); | |
} | |
} | |
private function print($num) | |
{ | |
$output = ""; | |
if ($this->isFizz($num)) { | |
$output .= "Fizz"; | |
} | |
if ($this->isBuzz($num)) { | |
$output .= "Buzz"; | |
} | |
$output = $output ?: $num; | |
echo "$output <br>"; | |
} | |
private function isFizz($num) | |
{ | |
return $num % 3 === 0; | |
} | |
private function isBuzz($num) | |
{ | |
return $num % 5 === 0; | |
} | |
} | |
$fizzBuzz = new FizzBuzz(); | |
$fizzBuzz->solve(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment