Home>

I want to execute a FizzBuzz function for integer values ​​between 1 and $max.
The return value depends on the number of a specific positive integer value received as an argument,
・ If the number is a multiple of 3, the return value is "Fizz"
・ If the number is a multiple of 5, the return value is "Buzz"
-If the number is a multiple of 3 and a multiple of 5, the return value is "FizzBuzz"
・ If none of the above is satisfied, the numerical value itself is used as the return value. It is a thing of the condition.
Since I want to run the fizzbuzz function with an integer value between 1 and $max, I want to leave out of the fizzbuzz function.
I do not print in the Fizzbuzz function, but want to print the return value after returning once.

Error message

Error message
None in particular
Points that do not meet the above specifications

Applicable source code
code
<? php
    function fizz_buzz () {
        $max = 100;
        for ($n = 1;$n<= $max;$n ++) {
            if ($n% 15 == 0) {
                print "FizzBuzz" .PHP_EOL;
            }
            elseif ($n% 3 == 0) {
                print "Fizz" .PHP_EOL;
            }
            elseif ($n% 5 == 0) {
                print "Buzz" .PHP_EOL;
            }
            else {
                print $n.PHP_EOL;
            }
        }
        }
    fizz_buzz ()
?>


Source code

None

Supplemental information (FW/tool version)

Cloud9

  • Answer # 1

    Since it looks like an assignment, answer the round throw. I will not explain.
    We do not take any responsibility for submitting the document as it is or not.
    Don't forget that the principle is "Don't write incomprehensible code".

  • Answer # 2

    I wrote it to be good without changing ini.


    By the way, I dare put a description that a beginner cannot explain.

Related articles