Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I believe you are running the script with out a webserver. I have tried it on my own and it seems to work except for some minor error that can be corrected. if you don't have a web server get one from <a href="http://www.wampserver.com/en/" rel="nofollow">here</a>. and install it. PHP won't run with out an interpreter and for it to work on a web browser you need a webserver.</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="common.css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;?php if ( isset($_POST["submitButton"] ) and isset( $_POST["guess"] ) ) { processForm(); } else { displayForm( rand( 1, 100 ) ); } function processForm() { $randNum = (int)$_POST["randNum"]; $guessLeft = (int)$_POST["guessLeft"]; $guess = (int)$_POST["guess"]; if ( $guess == $randNum ){ displaySuccess( $randNum ); } elseif ( $guess == 0 ){ displayFail( $randNum ); } elseif ( $guess &lt; $randNum ){ displayForm( $randNum, $guessLeft, "Too low, try again."); } elseif( $guess &gt; $randNum ){ displayForm( $randNum, $guessLeft, "Too high, try again."); } } function displayForm( $randNum, $guessLeft=5, $message="") { ?&gt; &lt;form action="" method="post"&gt; &lt;div&gt; &lt;input type="hidden" name="randNum" value="&lt;?php echo $randNum?&gt;" /&gt; &lt;input type="hidden" name="guessLeft" value="&lt;?php echo $guessLeft?&gt;" /&gt; &lt;?php if ( $message ) echo "&lt;p&gt;$message&lt;/p&gt;" ?&gt; &lt;p&gt;Guess my number. You have &lt;?php echo $guessLeft?&gt; &lt;?php echo ( $guessLeft == 1 ) ? "try" : "tries"?&gt; left to guess correctly.&lt;/p&gt; &lt;p&gt;What's your guess? &lt;input type="text" name="guess" value="" style="float: none; width: 3em;" /&gt; &lt;input type="submit" name="submitButton" value="Guess" style="float: none;" /&gt;&lt;/p&gt; &lt;/div&gt; &lt;/form&gt; &lt;?php } function displaySuccess( $randNum ) { ?&gt; &lt;p&gt;You guess it! &lt;?php echo $randNum?&gt; is correct!&lt;/p&gt; &lt;form action="" method="post"&gt; &lt;p&gt;&lt;input type="submit" name="tryAgain" value="Try Again" style="float: none;" /&gt;&lt;/p&gt; &lt;/form&gt; &lt;?php } function displayFail( $randNum ) { ?&gt; &lt;p&gt;You ran out of guesses! My number was &lt;?php echo $randNum?&gt;&lt;/P&gt; &lt;form action="" method="post"&gt; &lt;p&gt;&lt;input type="submit" name="tryAgain" value="Try Again" style="float: none;" /&gt;&lt;/p&gt; &lt;/form&gt; &lt;?php } ?&gt; &lt;/body&gt; </code></pre> <p></p> <p>here is the one i run...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload