Created
January 24, 2020 14:15
-
-
Save flangofas/56b7504c522655a6d6b38f84e86c312e to your computer and use it in GitHub Desktop.
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”.You can use JavaScript or PHP as those are the main languages we're using in SOCi. Use console.log() (in JavaScrip…
This file contains hidden or 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 | |
declare(strict_types=1); | |
function sayFizzBuzz(int $times = 0) | |
{ | |
$iterationPrint = ''; | |
for ($i = 0; $i <= $times; $i++) { | |
$iterationPrint = $i; | |
if ($i % 3 === 0 && | |
$i % 5 === 0) { | |
$iterationPrint = 'FizzBuzz'; | |
} | |
if (is_numeric($iterationPrint) && | |
$i % 3 === 0) { | |
$iterationPrint = 'Fizz'; | |
} | |
if (is_numeric($iterationPrint) && | |
$i % 5 === 0) { | |
$iterationPrint = 'Buzz'; | |
} | |
echo $iterationPrint . PHP_EOL; | |
} | |
} | |
sayFizzBuzz(100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment