Ok I have almost everything done beside write a timeout that asks users if they want to stop the game if they do not press the Guess button within 10 seconds. If the user selects OK, close the Web browser window.I can not figure it out this is what i have so far.
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<HTML>
<HEAD>
<TITLE>Guess the number</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
hiddenNumber = Math.round((Math.random() * 100))%100 + 1;
function checkGuess(obj) {
var status;
var guess=obj.value;
if (guess > hiddenNumber) {
status=(guess+" is Too high!\nTry again");
}
else if (guess < hiddenNumber) {
status=(guess+" is Too low!\nTry again");
}
else if (guess == hiddenNumber){
status=("Congratulations! You guessed the number!\n"+guess);
}
alert(status);
obj.value='';
}
function continueGame(){
var quit = confirm("Do you want to stop playing?");
if (quit == true)
window.close();
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</SCRIPT>
</HEAD>
<BODY>
<H1>Guessing Game</H1>
Guess a number between 1 - 100:
<FORM NAME="guessForm">
<INPUT TYPE="text" NAME="guessField">
<INPUT TYPE="button" VALUE=" Guess "
onClick="checkGuess(document.guessForm.guessField);">
</FORM>
</BODY>
</HTML>
1 Answer