Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <body>
- <fieldset>
- <label for="">Number 1:</label>
- <input type="text" id="firstNumber">
- <br><br>
- <label for="">Number 2:</label>
- <input type="text" id="secondNumber">
- <br><br>
- <button type="button" onclick="execute(add)"> + </button>
- <button type="button" onclick="execute(substract)"> - </button>
- <button type="button" onclick="execute(multiply)"> * </button>
- <button type="button" onclick="execute(divide)"> / </button>
- <h2 id="operationResult">
- </h2>
- </fieldset>
- <script>
- function add() {
- this.result = this.numberOne + this.numberTwo;
- }
- function substract() {
- this.result = this.numberOne - this.numberTwo;
- }
- function multiply() {
- this.result = this.numberOne * this.numberTwo;
- }
- function divide() {
- this.result = this.numberOne / this.numberTwo;
- }
- function receiverValues() {
- this.numberOne = Number(document.getElementById("firstNumber").value);
- this.numberTwo = Number(document.getElementById("secondNumber").value);
- this.result = 0;
- }
- function execute(operation) {
- receiverValues();
- operation();
- document.getElementById("operationResult").innerHTML = this.result;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement