Skip to content

Instantly share code, notes, and snippets.

@flangofas
Created January 24, 2020 14:15
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 flangofas/56b7504c522655a6d6b38f84e86c312e to your computer and use it in GitHub Desktop.
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…
<?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