Created
May 2, 2012 03:12
-
-
Save Jagst3r15/2573321 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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