SHARE
TWEET

Untitled

a guest Mar 25th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2.     <head>
  3.         <title>Jaan Markus Jahilo TA-17E</title>
  4.         <script language="Javascript">
  5.             window.onload = GenerateRandom;
  6.             var realResult = 0;
  7.             var value1 = 0;
  8.             var value2 = 0;
  9.  
  10.             function GenerateRandom() {
  11.                 value1 = document.getElementById("Value1").value = Math.round(Math.random()*10);
  12.                 value2 = document.getElementById("Value2").value = Math.round(Math.random()*10);
  13.             }
  14.            
  15.             function DoEquation(option) {
  16.                 switch (option) {
  17.                     case "add":
  18.                         realResult = value1 + value2;
  19.                         break;
  20.                     case "sub":
  21.                         realResult = value1 - value2;
  22.                         break;
  23.                     case "mul":
  24.                         realResult = value1 * value2;
  25.                         break;
  26.                     case "div":
  27.                         realResult = value1 / value2;
  28.                         break;
  29.                 }
  30.             }
  31.  
  32.             function CheckResult() {
  33.                 var result = document.getElementById("Result").value;
  34.                 if (result == realResult) {
  35.                     document.getElementById("correct").innerHTML = "Correct answer";
  36.                 }
  37.                 else {
  38.                     document.getElementById("correct").innerHTML = "Incorrect answer";
  39.                 }
  40.             }
  41.         </script>
  42.     </head>
  43.  
  44.     <body>
  45.         <h1>Performing Simple Math</h1>
  46.         <p>Value 1: <input type="text" id="Value1"></p>
  47.         <p>Value 2: <input type="text" id="Value2" value=" "></p>
  48.         <p>Result: <input type="text" id="Result" value=""></p>
  49.         <input type="button" value="+" onclick="DoEquation('add')"/>
  50.         <input type="button" value="-" onclick="DoEquation('sub')"/>
  51.         <input type="button" value="*" onclick="DoEquation('mul')"/>
  52.         <input type="button" value="/" onclick="DoEquation('div')"/>
  53.         <input type="button" value="Kontrolli vastust" onclick="CheckResult()"/>
  54.         <p id="correct"></p>
  55.  
  56.  
  57.     </body>
  58. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top