Can someone help? I am supposed to write a page that has write a small web page that uses JavaScript functions to play a number guessing game. The page should have two buttons, one labeled “Play”, and the other labeled “Guess” and an input control for the user to type a number.
When the user presses the “Play” button, a function should get and store a random number between 1 and 100. The user will try to guess this number. You may want to display this number on the status bar when testing the page. So write a line of code to do that, but comment out the line before you turn in the assignment. (That means, leave the line in, but make it a programming comment so that it does not run.)
When the user presses the “Guess” button, you should use a function to compare the number they entered (via the input control) to the random number picked earlier. The page should display one of three messages as appropriate. The messages are: “Too Low”, “Too High”, or “You Guessed It!”.
I’ve written the page and it works except for the IF function. Can someone take a look at it and see if they can figure out where I went wrong? Thanks ahead of time. ?
<?xml version=”1.0″ encoding=”iso-8859-1″?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “
<html xmlns=”
<head>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<script language=”JavaScript”>
var x = (Math.floor(Math.random()* (100 + 1)));
var y;
function changeStatusBar(){
window.status = x
}
function calculate(){
if (x < y)
{
document.write(“<b>Too High</b>”);
}
else if (x > y)
{
document.write(“<b>Too Low</b>”);
}
else
{
document.write(“<b>You Guessed It</b>”);
}
}
</script>
</head>
<body>
<form>
<input type=”button”
value=” Play “
onClick=”changeStatusBar();”>
</form>
<form>
<input type=”text” name=”y” size=”15″>
</form>
<form>
<input type=”button”
value=” Guess “
onClick=”calculate()”>
</form>
</body>
</html>