Title is self explanatory - I cannot figure out how to get this code working. Any help?
<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)
else if (guess < sum)
alert("Guess higher ");
When you pick two numbers between 1 and 10, the user is not then guessing a value between 1 and 10, the sum falls between 2 and 20 (inclusive).
You should throw in some logic that verifies that the user entered a number between 1 and 10. Not critical, but it is odd to see "guess lower" when I enter a letter or special character instead of a number.