7/7 - What's wrong with my code please?


Can anyone help me with these issues?
I'm trying to do a dice-roll 'do while' code which is throwing an error. Can I include an 'if' or 'else' statement inside a 'do while' statement?
Do I have to include 'endwhile' here? Also, can I use both kinds of syntax in the same code (curly braces and the other ones at each end) or does that confuse the system? I'm a bit confused as to how many braces to put in.

$rollCount = 0;
$sixRoll = 0;

    $roll = rand(1,6); 
    $rollCount ++;   
         $roll != 6;
    $roll == 6; 
echo "We rolled six";


Hi this is a do-while loop for example. it runs once

$i = 0;
do {
    echo $i;
} while ($i > 0);

What you type in the do part is your thing. And yes it could be a if else statement


I am not sure what you are trying to do here but lets try to clean up the code a little and go from there, maybe? Inside the do-while loop ur generating a random number hopefully bet 1 and 6. Maybe not be the right way to call ftn but that can wait. Next you try to increment rollcount and you want to do this repeatedly until roll is not equal to 6. Ok . Then add a "}" before the while. Change the "}" after the while to a "(" and change the "]" b4 the else to a ")". Also remove the semicolon after '$roll !=6' and remove everything from the else up to the echo but not including the echo'
The question is now what roll $rollCount play in this scenario. is it how many times a six was generated or how many rolls it took to generate a six?
I recall that while endwhile; etc is an alternative way to loop to make html, code etc consistent, pretty etc. Probably should not mix the two.
Ok so we roll a six, break the loop and now what? Print "we rolled a six" and Maybe print how many rolls it took to generate that six as in printing(echo'ing rollcount). Make changes and check the syntax for a call to rand() just to be sure.


dont forget the semicolon after the 'while()' lke do{ 'do something' } while( 'until something else is or isnt');


did this code work for you because it is not working for me i dont know why


Try refreshing and seeing if it works. PHP has some problems in it's lessons, and codecademy in general seems to be having some server issues. (Lots of people!)