logo CodeStepByStep logo

parameter_mystery11

Language/Type: PHP parameter mystery parameters return
Author: Mehran Sahami (added by Melissa Hovik on 2018/01/05)

The following console program uses parameters and returns to produce five lines of output. What are they?

function ghost($x) {
    $y = 0;
    for ($i = 1; $i < $x; $i *= 2) {
        $y = witch($y, skeleton($x, $i));
    }
    print("ghost: x = $x, y = $y\n");
}

function witch($x, $y) {
    $x = 10 * $x + $y;
    print("witch: x = $x, y = $y\n");
    return $x;
}

function skeleton($x, $y) {
    return $x / $y % 2;
}

ghost(13);
line 1
line 2
line 3
line 4
line 5

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.