Ok, I’m working on a number guessing game that gives you three tries to guess a number that is randomly selected from 1-10. If you get the answer right within three tries, you get a point. If you don’t, the computer gets a point. I need there to also be a save and load button that sets up and reads a cookie respectively that saves the current guess, the score, the random number, and the message. Here’s what I have so far. I haven’t established the cookie, or the save and load buttons. I’m just not sure how to go about setting it up. Cookies confuse me…?
[CODE]
<?xml version=”1.0″?>
<!DOCTYPE html
PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type”
content=”text/html; charset=ISO-8859-1″/>
<meta name=”Author” content=”Andy Lowe”/>
<meta http-equiv=”Content-Script-Type”
content=”application/ecmascript”/>
<script type=”application/ecmascript”>
/* <![CDATA[ */
function Onload() {
var guesses;
var random = Math.floor(Math.random() * 10) + 1;
var userpoints = parseFloat(0);
var comppoints = parseFloat(0);
form1 = document.forms[‘GameForm’];
form1.CompScore.value=comppoints;
form1.UserScore.value=userpoints;
}
/* ]]> */
</script>
<title>Number Game</title>
</head>
<body onload=Onload()>
<form name=”GameForm” action=”#”>
<table width=”650″ cellspacing=”1″ cellpadding=”2″ border=”0″ align=”center”>
<tr>
<th style=”text-align:center”>
<p>Secret Number Guessing Game</p>
</th>
</tr>
<td>
<p>Welcome to the Secret Number Guessing Game! Here are the rules:</p>
<p>
A number will be randomly selected from 1-10. You will have three tries to guess the number. If you guess correctly by the third try, you get a point! However, if you do not guess in three tries, the computer gets a point. You will be notified along the way whether you guess is too high or too low.</p>
</td>
</table>
<br/>
<table align=”center” cellpadding=”10″ border=”5″ cellspacing=”1″ width=”400″>
<tr>
<td style=”text-align:right”>
User Guess:
</td>
<td>
<input type=”text” name=”UserGuess” value=”” size=”30″ />
</td>
</tr>
<tr>
<td style=”text-align:right”>
Message:
</td>
<td>
<input type=”text” name=”Message” value=”Type your guess in the box above” size=”30″ />
</td>
</tr>
</table>
<br/>
<table align=”center”>
<tr>
<td>
<input type=”button” name=”Submit” value=”submit” onclick=Onclick() />
</td>
<tr>
</table>
<br/>
<table cols=”2″ align=”center” cellpadding=”10″ border=”5″ cellspacing=”1″ width=”400″>
<tr>
<th>
Computer Score
</th>
<th>
User Score
</th>
</tr>
<tr>
<td>
<input type=”text” name=”CompScore” value=”” />
</td>
<td>
<input type=”text” name=”UserScore” value=”” />
</td>
</tr>
</table>
</form>
</body>
</html>