Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>
  6. Assingment 7
  7. </title>
  8. <style>
  9. body{background-color:lightcoral;
  10. font-size:24px;}
  11.  
  12. input{font-size:24px;}
  13.  
  14. input:hover{background-color:aquamarine;}
  15. </style>
  16.  
  17.  
  18.  
  19.  
  20. </head>
  21. <body>
  22. <h1>Math with JavaScript</h1>
  23. <input type="text" size="5" id="box1">
  24.  
  25. <span id="sign">
  26. &nbsp;
  27. </span>
  28.  
  29. <input type="text" size="5" id="box2">
  30.  
  31. =
  32.  
  33. <span id="output">
  34. &nbsp;
  35. </span>
  36. <br><br>
  37.  
  38. <input type="button" value="Add"
  39. onclick="addNumbers()";>
  40.  
  41. <input type="button" value="Subtract"
  42. onclick="subtractNumbers()";>
  43.  
  44. <input type="button" value="Multiply"
  45. onclick="multiplyNumbers()";>
  46.  
  47. <input type="button" value="Divide"
  48. onclick="divideNumbers()";>
  49.  
  50.  
  51.  
  52. <script>
  53. function addNumbers(){
  54. //make a variable for the value of box1
  55. var value1=parseFloat(document.getElementById("box1").value);
  56. //make a variable for the value of box2
  57. var value2=parseFloat(document.getElementById("box2").value);
  58. //make a variable for total
  59. var total= value1+value2;
  60. //put total and output span, show the total
  61. document.getElementById("output").innerHTML=total;
  62. //put a + sign in the sign span
  63. document.getElementById("sign").innerHTML="+"
  64. }
  65.  
  66. function subtractNumbers(){
  67. //make a variable for the value of box1
  68. var value1=parseFloat(document.getElementById("box1").value);
  69. //make a variable for the value of box2
  70. var value2=parseFloat(document.getElementById("box2").value);
  71. //make a variable for total
  72. var total= value1-value2;
  73. //put total and output span, show the total
  74. document.getElementById("output").innerHTML=total;
  75. //put a + sign in the sign span
  76. document.getElementById("sign").innerHTML="-"
  77. }
  78.  
  79. function multiplyNumbers(){
  80. //make a variable for the value of box1
  81. var value1=parseFloat(document.getElementById("box1").value);
  82. //make a variable for the value of box2
  83. var value2=parseFloat(document.getElementById("box2").value);
  84. //make a variable for total
  85. var total= value1*value2;
  86. //put total and output span, show the total
  87. document.getElementById("output").innerHTML=total;
  88. //put a + sign in the sign span
  89. document.getElementById("sign").innerHTML="X"
  90. }
  91.  
  92. function divideNumbers(){
  93. //make a variable for the value of box1
  94. var value1=parseFloat(document.getElementById("box1").value);
  95. //make a variable for the value of box2
  96. var value2=parseFloat(document.getElementById("box2").value);
  97. //make a variable for total
  98. var total= value1/value2;
  99. //put total and output span, show the total
  100. document.getElementById("output").innerHTML=total;
  101. //put a + sign in the sign span
  102. document.getElementById("sign").innerHTML="<span>&#247;</span>"
  103. }
  104.  
  105. function clear(){
  106. document.getElementById("")
  107.  
  108.  
  109.  
  110.  
  111.  
  112. }
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. </script>
  120.  
  121.  
  122. </body>
  123. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement