Skip to content

Instantly share code, notes, and snippets.

@Jagst3r15
Created May 2, 2012 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jagst3r15/2573321 to your computer and use it in GitHub Desktop.
Save Jagst3r15/2573321 to your computer and use it in GitHub Desktop.
<html>
<head>
<title> Lab 11 - #3 </title>
</head>
<script>
function play () {
play();
var guess = -1; // Set guess to a value outside the range of valid values
for (i=1; i <= 5; i++) {
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;
// Use a while loop
while (guess != sum)
{
guess = prompt("Enter the correct answer for "+num1+" + "+num2, '');
if (guess == sum)
{
alert("Correct!");
}
else if (guess < sum)
{
alert("Guess higher ");
}
else
{
alert("Guess lower");
}
}
}
}
if(confirm("play again")) play();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment