Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

php guessing game help

$
0
0

hello guys

i have some guessing game code that works fine

i just need a few things adding to it that i dont know how to do if some body could please show me how.

its just a simple number game where the user has to keep guessing numbers between 1 and 10 till they get it right.

could somebody please how me how to add to the code so that.

- there is a counter that tells the user how many guesses they have had.

- the program stops at 7 guesses.

 

thanks guys 

 

my code is

 

 

 

if(isset($_POST['guess'])) {
    $guess = intval($_POST['guess']);
    $secret = intval($_POST['secret']);
 
    $output = "";
    
    if($guess == $secret)
    {
        $output .= "<h1>Correct!</h1>";
 
        $output .= "<a href='guessinggame.php'>Play again</a>";
    }
    elseif($guess < $secret)
    {
        $output .= "<h1>Your answer was too low. Please try again!";
    }
    else
    {
        $output .= "<h2>Your answer was too high. Please try again!</h2>";
    }
}
 
 
?>

Viewing all articles
Browse latest Browse all 13200

Trending Articles