0% found this document useful (0 votes)
28 views2 pages

JavaScript Calculator Script

Uploaded by

foojunhee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

JavaScript Calculator Script

Uploaded by

foojunhee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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