1. JavaScript Program to Calculate Addition and Subtraction of two Numbers.
How does this program work?
- In this program you will learn about how to find addtion and subtraction of two numbers using JavaScript.
- Initially The integer entered by the user is stored in two variables a,b.
- After that by using the given formula you will get output.
Here is the code
<html>
<head>
<title>JavaScript Program to calcualte Addition and Subtraction of two numbers</title>
</head>
<body>
<table>
<tr>
<td> <input type="text" name="a" id="first" placeholder="Enter first value"> </td>
</tr>
<tr>
<td> <input type="text" name="b" id="second" placeholder="Enter second value"> </td>
</tr>
<tr>
<td> <button onclick="add ( )">Submit</button> </td>
</tr>
</table>
<div id="add"></div>
<div id="sub"></div>
</body>
<script type="text/javascript">
function add( )
{
var a,b,Add,Sub;
a = parseInt(document.getElementById ("first").value);
b = parseInt(document.getElementById ("second").value);
Add = a+b; //Add two numbers
Sub = a-b; //Subtraction of two numbers
//To print the result
document.getElementById ("add") .innerHTML ="Addition : "+Add;
document.getElementById ("sub").innerHTML ="Subtraction : "+Sub;
}
</script>
</html>