Absolutely nothing happens when I click on the button, and I know NOTHING about Java. Need serious help!
The user is supposed to arbitrarily type a number (1-5) and see if it's the same one that JavaScript generates. The function "secretNum" is supposed to be a global variable, but I don't have a clue as to what that means. Anyways, an alert should pop up saying either congrats or try again.
Code:
<html>
<head>
<title>Guessing Game</title>
<script type="text/javascript">
function setUp ()
{
secretNum = 1+Math.floor(5*Math.random());
alert = (secretNum);
}
function checkGuess ()
{
userGuess = document.IfForm.guessBox.value;
userGuess = parseFloat(userGuess);
// get value from text box
if (secretNum == userGuess)
{alert ("Correct!");}
else
{alert ("Sorry, Try Again");}
}
</script>
</head>
<body style="text-align:center" onLoad="setUp();">
<h2>Guess the Number From 1 to 5</h2>
<form name="IfForm">
Enter Your Guess:
<input type="text" size="5" name="guessBox" value="" />
<br />
<input type="button" value="Check Guess" onClick="checkGuess" />
</form>
</body>
</html>