This code is a simple calculator. Enter 2 numbers and hit the required operation to get the output and there is nothing wrong in this code. But, I'm trying to find the possible ways of reducing the JavaScript code to the shortest.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function add(){
var a = parseInt(document.getElementById('no1').value);
var b = parseInt(document.getElementById('no2').value);
document.write(a+b);
}
function sub(){
var a = document.getElementById('no1').value;
var b = document.getElementById('no2').value;
document.write(a-b);
}
function mult(){
var a = document.getElementById('no1').value;
var b = document.getElementById('no2').value;
document.write(a*b);
}
function div(){
var a = document.getElementById('no1').value;
var b = document.getElementById('no2').value;
document.write(a/b);
}
</script>
</head>
<body>
<input type="text" id="no1">
<input type="text" id="no2">
<input type="button" value="ADD" onclick="add()">
<input type="button" value="SUB" onclick="sub()">
<input type="button" value="MULT" onclick="mult()">
<input type="button" value="DIV" onclick="div()">
</body>
</html>