Q.No.6 - Create an HTML form that accepts two numbers from the user. Write a program to sum and multiply of two numbers using JavaScript.
Previous year question
Sol.-
<html>
<head>
<title>Javascript- Examcomp</title>
</head>
<body>
<h1>Addition and Subtraction using Javascript</h1>
Enter Your 1st Number : <input id="f1">
<br><br>
Enter Your 2nd Number : <input id="f2">
<br><br>
<button onclick ="sum()">Addition</button> <button onclick="sub()">Subtration</button>
Result Here: <span id="result"></span>
<script>
function sum() {
var a = document.getElementById('f1').value;
var b = document.getElementById('f2').value;
var c = parseInt(a)+ parseInt(b);
document.getElementById("result").innerHTML=c;
}
function sub() {
var a = document.getElementById('f1').value;
var b = document.getElementById('f2').value;
var c = parseInt(a) - parseInt(b);
document.getElementById("result").innerHTML=c;
}
</script>
</body>
</html>
OUTPUT:
![](pr2-j1o.png)