Im learning PHP and I cant get this piece of code to work, I am just beginning to get into php and cant figure this out. The online validator reports no issues found but it sets of an infinite loop for me. Can some one tell me why the $eggUsage is not being subtracted from the $eggs.
Thank you :-)
<?php
$eggs = 12;
$eggUsage = 0;
while($eggs - $eggUsage > 0) {
$eggUsage = rand(0, 1, 2, 3, 4);
$eggs = $eggs - $eggUsage;
echo "You have {$eggs} left";
}
if ($eggs < 4) {
$eggUsage = rand(0, 1, 2, 3, 4);
$eggs == $eggs - $eggUsage;
echo "You are almost out. BUY EGGS!";
}
echo "<p>Congratulations, you are out of eggs.</p>"
?>
Aucun commentaire:
Enregistrer un commentaire