Part 5 in how do you do-while


#1

The second coin game:

The text says that is would stop at "H", but it actually does stop at "T".
I did start writing in the script and now it crashes over and over again.


#2

Can you post your code so i can check it?


#3

The only thing i changed was the line:
if ($flip = 1){

Before is was:
if ($flip){

<?php
$flipCount = 0;
do {
    $flip = rand(0,1);
    $flipCount ++;
    if ($flip = 1){
        echo "<div class=\"coin\">H</div>";
    }
    else {
        echo "<div class=\"coin\">T</div>";
    }
} while ($flip);
$verb = "were";
$last = "flips";
if ($flipCount == 1) {
    $verb = "was";
    $last = "flip";
}
echo "<p>There {$verb} {$flipCount} {$last}!</p>";
?>

#4

that is where you made a mistake:

if ($flip = 1){

you assign a value of one here to $flip, so now this line:

while ($flip);

will always be true (since $flip is always one, which is true)
you want to compare:

if ($flip == 1)

you should use two equal signs. You could just have left it the way it was, 1 is true, and 0 is false so if($flip){ would have been fine


#5

Yes, but I can't change anything. They give me directly a:

"Something went wrong :frowning:
Click Close to try again or refresh the page."

Even the reset code option doesn't work after that.


#6

Did you refresh the page? Did you re-open the page?


#7

I have tried to refresh it alot (f5 key). closing and reloading the page does not help either.


#8

Then i am out of ideas, you could try a different browse all together


#9

Opening it in another browser made the page forget my previous changes at the not completed sesions.

Thank you for your time.