Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <fieldset>
  5. <label for="">Number 1:</label>
  6. <input type="text" id="firstNumber">
  7. <br><br>
  8. <label for="">Number 2:</label>
  9. <input type="text" id="secondNumber">
  10. <br><br>
  11. <button type="button" onclick="execute(add)"> + </button>
  12. <button type="button" onclick="execute(substract)"> - </button>
  13. <button type="button" onclick="execute(multiply)"> * </button>
  14. <button type="button" onclick="execute(divide)"> / </button>
  15. <h2 id="operationResult">
  16. </h2>
  17. </fieldset>
  18.  
  19. <script>
  20. function add() {
  21. this.result = this.numberOne + this.numberTwo;
  22. }
  23.  
  24. function substract() {
  25. this.result = this.numberOne - this.numberTwo;
  26. }
  27.  
  28. function multiply() {
  29. this.result = this.numberOne * this.numberTwo;
  30. }
  31.  
  32. function divide() {
  33. this.result = this.numberOne / this.numberTwo;
  34. }
  35.  
  36. function receiverValues() {
  37. this.numberOne = Number(document.getElementById("firstNumber").value);
  38. this.numberTwo = Number(document.getElementById("secondNumber").value);
  39. this.result = 0;
  40. }
  41.  
  42. function execute(operation) {
  43. receiverValues();
  44. operation();
  45. document.getElementById("operationResult").innerHTML = this.result;
  46. }
  47. </script>
  48. </body>
  49. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement