Im trying to make a php guessing game where when you enter a number under 10 it will show a for loop of 100 random numbers 1 - 10 and then it will output the number of times it guesses the number.
I have the loop working but its not showing the amount of time it guesses the number.
<?php
$counter = 0;
$num = $_POST["num"];
for ($i=0; $i <=100;$i++) {
$randomNum = rand(1,10);
if ($randomNum == $num) {
echo "$randomNum ";
$counter++;
}
else
{
echo"$randomNum ";
}
}
echo"<h2> there are $counter</h2>";
?>
<!DOCTYPE html>
<html>
<head>
</head>
</body>
</html>
<h1>Enter a Number and see if you can guess it</h1>
<body>
<form action="finalresults.php" method="post">
<h2>Enter a number under ten</h2>
<input type="text" name="num">
<input type="submit" value="Now I will guess">
</form>
</body>
</html>
I want the output to look like the image attached
Aucun commentaire:
Enregistrer un commentaire