PHP 6 sided die counting number of rolls
I'm very new to PHP and I am stuck. I'm trying an exercise where I am rolling a 6 sided die and counting the number of times it is rolled until there is X number of 1s rolled in a row. The code I have up until this point is:
<!DOCTYPE html>
<html>
<head>
<title>Practice</title>
<link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
<?php
//Practiceing while and do while loops
$onecount = 0
$rollcount = 0
while ($onecount < 7) {
$roll = rand(1,6);
$rollcount ++;
if ($roll!=1) {
echo {$rollcount};
}
else {
$roll=1;
$onecount ++;
}
}
?>
</body>
</html>
I feel like I'm missing something very simple but I didn't know what else to do.
Thank you in advance!
Answer
Solution:
You need to reset your
$onecount
variable when the role isn't 1, since the streak is broken each time it's a different number. Also, you probably want to do something after the while loops finishes and you have your total roll count.