Skip to content

Commit 0c4e895

Browse files
authored
Added guess_number.php
A simple PHP based guessing game, where user guesses a number from 1 to 10. The computer generates a random number from 1 to 10. If the number that the user enters matches the number that the computer generates, the user has guessed the correct number. If the number that the user has entered does not match the number that the computer has generated, the user is told that this is the incorrect number and to try again.
1 parent 08860d7 commit 0c4e895

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Random Number/guess_number.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
$number= $_POST['number'];
4+
5+
$submit = $_POST['submit'];
6+
7+
8+
$randomNumber= mt_rand(1,10);
9+
10+
11+
?>
12+
13+
14+
<form action="" method="POST">
15+
Guess a Number Between 1 and 10:
16+
<input type="text" name="number" value='9'/> <br><br>
17+
18+
Result:
19+
<?php
20+
if ($submit){
21+
22+
if (($number > 0) && ($number <11)){
23+
if ($number != $randomNumber)
24+
{
25+
echo "Incorrect guess. The correct number was $randomNumber. Try again";
26+
}
27+
else
28+
{
29+
echo "$randomNumber is the correct guess. You got it right.";
30+
}
31+
}
32+
33+
}
34+
35+
?>
36+
<br><br>
37+
<input type="submit" name="submit" value="submit"/><br><br>
38+
</form>

0 commit comments

Comments
 (0)