You are on page 1of 2

Experiment – 3

3-
Write a Javascript to design a simple calculator to perform the following operations:
Sum, Product, Difference and Quotient.

CODE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Calculator using html, css, bootstrap and javascript</title>
<script type="text/javascript">
function SubmitClick(){
var a = parseInt(document.getElementById("num1").value);
var b = parseInt(document.getElementById("num2").value);
var sum = a + b;
var product= a * b;
var diff = a - b;
var quotient = a / b;
document.getElementById("sum").value = sum;
document.getElementById("product").value = product;
document.getElementById("diff").value = diff;
document.getElementById("quotient").value = quotient;
}
</script>
</head>
<body style="background-color:lightblue;">
<div class="container">
<h2> Simple Calculator </h2>
<form method="get" onsubmit="event.preventDefault(); SubmitClick();">
Enter first number: &nbsp;<br>
<input type="number" id="num1" name="num1"> <br>
Enter Second number: &nbsp;<br>
<input type="number" id="num2" name="num2"> <br>
The Sum of two numbers is: &nbsp;<br>
<input type="number" id="sum" name="sum"> <br>
The Product of two numbers is: &nbsp;<br>
<input type="number" id="product" name="product"> <br>
The difference of two numbers is: &nbsp;<br>
<input type="number" id="diff" name="diff"> <br>
The quotient of two numbers is: &nbsp;<br>
<input type="number" id="quotient" name="quotient"> <br>
<button type="submit"> Calculate </button>
</form>
</div>
</body>
</html>

OUTPUT

Submitted By:-
Swapneswar Mishra
2101020552
CSI21032
Group- 08

You might also like