JavaScript Program to add of two numbers
Program
<!DOCTYPE html>
<html>
<head>
<title>Add Two Numbers</title>
<script>
function calculateSum()
{
var a = document.getElementById("firstNum").value;
var b = document.getElementById("secondNum").value;
var sum = parseInt(a) + parseInt(b);
document.getElementById("result").innerHTML = sum;
}
</script>
</head>
<body>
<h2>Add two numbers</h2>
<label>Enter the value of a: </label>
<input type="number" id="firstNum" name="firstNum" /><br>
<label>Enter the value of b: </label>
<input type="number" id="secondNum" name="secondNum" /><br>
<button type="button" onClick="calculateSum()">Add</button><br>
<p>Result: <span id="result" style="color: red;"></span></p>
</body>
</html>
Output
Add two numbers
Result: