http://php.flashwebhost.com/vineesh/day8/day_8_ex_5.php
PHP Code:
<html>
<body>
<h1 style="color:blue">HI..LETS PLAY A NUMBER GUESSING GAME<h1>
<?php
if (isset($_GET['serverNumber'])) {
$serverNumber = $_GET['serverNumber'];
} else {
$serverNumber = rand(1,6);
}
if (isset($_GET['userNumber'])) {
$userNumber = $_GET['userNumber'];
if ($serverNumber > $userNumber) {
echo '<h2 style="color:red">Number you entered is small</h2>';
} else if ($serverNumber < $userNumber) {
echo '<h2 style="color:red">Number you entered is big</h2>';
} else {
echo '<h2 style="color:green">Hey..congratulations!, you win.</h2>';
}
}
?>
<form method="GET" action="">
<font style="color:green">Enter your Number</font>
<input type="text" name='userNumber'>
<button type="submit">Check now!!!</button>
<input type="hidden" name="serverNumber" value="<?php echo $serverNumber ?>">
</form>
<h2 style="color:orange"><u>Instructions for players:</u></h2>
<pre style="color:green">
1. The game will automatically pick a number between 1 and 7.
2. You need to guess the number and enter into the box, then click on 'check now' button.
3. If you are wrong, the game will give you a hint.
4. Try to win the game within 3 attempts.
and finally, all the best..!
</pre>
</body>
</html>
Bookmarks