Here is my working solution to 7. All On Your Own!


#1

7. All On Your Own!

    <?php
        $rollCount = 0;
        do {
            $roll = rand(1,6);
            $rollCount ++;
            if ($roll !== 6) {
                echo "<p>You rolled a " . $roll . ".</p>";
            }
            else {
                echo "<p>You rolled a " . $roll . ". We have a winner!</p>";
            }
        } while ($roll != 6);
        $last = "roll!";
        if ($rollCount > 1) {
            $last = "rolls.";
        }
        echo "<p>You won in " . $rollCount . " " . $last . "</p>";      
    ?>

Hope this helps you figure out where you're going wrong.


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.