This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by manujanshu.pal
over 8 years

Please help me on the below code. Also refer to the note in the description.

Note: Moreover, as soon as i start to type the while statement, it throws an error saying that, something went wrong, and nothing happens after that.

$rollcount =0; do { $roll = rand(1,6); $rollcount++; if($roll<6){ echo “

Dice rolled $roll

“; }else{ echo “

You gotta six

“; } } while ($roll<=6); $verb = “were”; $last = “rolls”; if($rollcount = 1){ $verb = “was”; $last = “roll”; echo “

There $verb $rollcount $last

“; }else{ echo “

There $verb $rollcount $last

“; }

Answer 55969a86e39efe29e000049c

0 votes

Permalink

The first thing you should know while writing PHP in codecademy is, it does not wait for you to complete your code. It updates the code immediately when you write it, so you gotta be careful when you write it. This means that when you write white($var) { }, the code automatically runs and it gets really annoying.

So what I do about this is, I give a different condition before writing the loop.

This means, when actually I want the loop to stop when $num < 3, I would put a different condition and then, when it is complete and the loop gets an end, I replace the condition.

while ($var)
{
    $var = false;
    //Now, I can write the actual code here without getting interrupted
    //and when my job is over, I can delete the third line and change the
    //condition for the white loop to get the correct result.
}

Another thing you can do is writing the code in any text editor like notepad, and then copying and pasting the code from notepad into codecademy. It is less time consuming and not complex like the previous one mentioned.

You’re welcome.

points
Submitted by n-kartha
over 8 years