0% found this document useful (0 votes)
8 views

Calculator Script

Uploaded by

foojunhee
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Calculator Script

Uploaded by

foojunhee
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

HTML

<h2> First number: </h2>

<input type="text" id="firstNum">

</input>

<h2> Second number: </h2>

<input type="text" id="secondNum">

</input>

<br>

<button onclick="Plus()">Plus</button>

<button onclick="Minus()">Minus</button>

<button onclick="Divide()">Divide</button>

<button onclick="Times()">Times</button>

<h2>Answer:</h2>

<div>

<h2 id="Answer">

</h2>

</div>

JavaScript

function Plus()

Num1 = document.getElementById("firstNum").value;

Num2 = document.getElementById("secondNum").value;

document.getElementById("Answer").innerHTML = Number(Num1) + Number(Num2);

}
function Minus()

Num1 = document.getElementById("firstNum").value;

Num2 = document.getElementById("secondNum").value;

document.getElementById("Answer").innerHTML = Number(Num1) - Number(Num2);

function Divide()

Num1 = document.getElementById("firstNum").value;

Num2 = document.getElementById("secondNum").value;

document.getElementById("Answer").innerHTML = Number(Num1) / Number(Num2);

function Times()

Num1 = document.getElementById("firstNum").value;

Num2 = document.getElementById("secondNum").value;

document.getElementById("Answer").innerHTML = Number(Num1) * Number(Num2);

You might also like