
Untitled
By: a guest on
May 1st, 2012 | syntax:
None | size: 0.71 KB | hits: 16 | expires: Never
<html>
<head>
<title> Addition </title>
</head>
<script>
var guess = -1; // Set guess to a value outside the range of valid values
var num1 = parseInt(Math.random()*10); // get a number between 0 and 9
var num2 = parseInt(Math.random()*10); // get a number between 0 and 9
sum = num1 + num2;
alert("(to help test) The correct answer is " + sum); // Just to help test
// Use a while loop
while (guess != sum)
{
guess = prompt("Guess a number from 1 to 10", "");
if (guess == sum)
{
alert("Correct!");
}
else if (guess < sum)
{
alert("Guess higher ");
}
else
{
alert("Guess lower");
}
}
</script>
</body>
</html>