Thu Jun 09 2022
Arithmetic Operations
JavaScript1349 views
File Name: JavaScript-Arithmetic-operations.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Basic Calculation in JavaScript</title>
<style>
div {
font-size: 25px;
margin: 20px;
}
input[type=text] {
padding: 5px 10px;
font-size: 18px;
}
button {
font-size: 18px;
padding: 5px 20px;
}
</style>
<script>
function calculate() {
let a = (document.getElementById("num1").value * 1);
let b = (document.getElementById("num2").value * 1);
document.getElementById("sum").innerHTML = a + b;
document.getElementById("sub").innerHTML = a - b;
document.getElementById("mul").innerHTML = a * b;
document.getElementById("div").innerHTML = a / b;
document.getElementById("mod").innerHTML = a % b;
}
</script>
</head>
<body>
<input type="text" id="num1" />
<input type="text" id="num2" />
<button type="button" onclick="calculate()">Calculate</button>
<div>
<strong>Sum:</strong> <span id="sum"></span>
</div>
<div>
<strong>Subtract:</strong> <span id="sub"></span>
</div>
<div>
<strong>Multiplication:</strong> <span id="mul"></span>
</div>
<div>
<strong>Division:</strong> <span id="div"></span>
</div>
<div>
<strong>Modulus:</strong> <span id="mod"></span>
</div>
</body>
</html>
Result Screenshot(s)
Author:Geekboots