Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 0.71 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <html>
  2. <head>
  3. <title> Addition </title>
  4. </head>
  5. <script>
  6.        
  7.     var guess = -1; // Set guess to a value outside the range of valid values
  8.         var num1 = parseInt(Math.random()*10); // get a number between 0 and 9
  9.         var num2 = parseInt(Math.random()*10); // get a number between 0 and 9
  10.         sum = num1 + num2;
  11.                
  12.     alert("(to help test) The correct answer is " + sum);  // Just to help test
  13.         // Use a while loop
  14.         while (guess != sum)
  15.         {
  16.        
  17.                 guess = prompt("Guess a number from 1 to 10", "");
  18.                 if (guess == sum)
  19.                 {
  20.                         alert("Correct!");
  21.                        
  22.                 }
  23.                 else if (guess < sum)
  24.                 {
  25.                         alert("Guess higher ");
  26.                 }
  27.                 else
  28.                 {
  29.                         alert("Guess lower");
  30.                 }
  31.         }      
  32.                    
  33. </script>
  34. </body>
  35. </html>