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>

&lt;h2&gt;Add two numbers&lt;/h2&gt;
&lt;label&gt;Enter the value of a: &lt;/label&gt;
&lt;input type=&quot;number&quot; id=&quot;firstNum&quot; name=&quot;firstNum&quot; /&gt;&lt;br&gt;
&lt;label&gt;Enter the value of b: &lt;/label&gt;
&lt;input type=&quot;number&quot; id=&quot;secondNum&quot; name=&quot;secondNum&quot; /&gt;&lt;br&gt;
&lt;button type=&quot;button&quot; onClick=&quot;calculateSum()&quot;&gt;Add&lt;/button&gt;&lt;br&gt;
&lt;p&gt;Result: &lt;span id=&quot;result&quot; style=&quot;color: red;&quot;&gt;&lt;/span&gt;&lt;/p&gt;

</body> </html>

Output

Add two numbers



Result: