Results 1 to 10 of 16

Thread: Day 8 - Lets Make A Game - Part 1 - Become PHP Expert in 30 days

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #14
    Join Date
    Feb 2010
    Posts
    35

    Red face between 1 and 3

    PHP Code:
    <html>
    <body>

    <h1>Number Guessing Game.</h1>

    <?php

    if (isset($_GET['secretNumber'])) {
        
    $secretNumber $_GET['secretNumber'];
    } else {
        
    $secretNumber rand(1,3);
    }

    if (isset(
    $_GET['userNumber'])) {
        
    $userNumber $_GET['userNumber'];

        if (
    $secretNumber $userNumber) {
            echo 
    '<h1 style="color:red">Your number is too SMALL.</h1>';
        } else if (
    $secretNumber $userNumber) {
            echo 
    '<h1 style="color:blue">Your number is too BIG.</h1>';
        } else {
            echo 
    '<h1 style="color:green">You win the game.</h1>';
        }
    }

    ?>

    <form method="GET" action="">
        Enter Number: <input name="userNumber" type="text">
        <button type="submit">Check</button>
        <input type="hidden" name="secretNumber" value="<?php echo $secretNumber?>">
    </form>

    <h2>How to Play:</h2>

    <pre>
    * Server will pick a secret number between 1 and 3.
    * You guess what number it is.
    * If your guess is too high or too low, Server will give you a hint.
    * See how many turns it takes you to win!
    </pre>

    </body>
    </html>
    Last edited by betheman; 09-08-2015 at 05:38 AM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •