12. Make a basic calculator, which can apply on two operands.
<html>
<head>
<script>
function add() {
var a = document.getElementById("a1").value;
var b = document.getElementById("a2").value;
var c = +(a + b);
document.getElementById("out").innerHTML = "Addition is " + c;
}
function sub() {
var a = document.getElementById("a1").value;
var b = document.getElementById("a2").value;
var c = a - b;
document.getElementById("out").innerHTML = "Subtraction is " + c;
} function mul() {
var a = document.getElementById("a1").value;
var b = document.getElementById("a2").value;
var c = a * b;
document.getElementById("out").innerHTML = "Multipliction is" + c;
} function divi() {
var a = document.getElementById("a1").value;
var b = document.getElementById("a2").value;
var c = a / b;
document.getElementById("out").innerHTML = "Division is" + c;
}
</script>
</head>
<body>
<div id="inp">
<center>
<h1>INPUTS </h1> <br><br>
Enter the 1st number <input type=value id="a1">
<br><br>
Enter the 2nd number <input type=value id="a2">
</center>
</div>
<hr>
<div id="oper">
<center>
<button type="button" onclick="add()">
<pre> + </pre>
</button>
<button type="button" onclick="sub()">
<pre> - </pre>
</button>
<button type="button" onclick="mul()">
<pre> * </pre>
</button>
<button type="button" onclick="divi()">
<pre> / </pre>
</button>
</center>
</div>
<hr>
<div id="output">
<center>
<h1> OUTPUT </h1>
<br><br><br>
<h1 id="out">
</h1>
</center>
</div>
</body>
</html>
Output
No Output Available