JavaScript

Sum of two numbers in JavaScript

In this tutorial we will discover how to calculate the sum of two numbers entered by the user in Javascript.
 

Program to calculate the sum of two numbers in JavaScript
<!doctype html>
<html>
   <head>
      <script>
         function sumOfNbr(){
             var nbr1, nbr2, sum;
             nbr1 = Number(document.getElementById("nbr1").value);
             nbr2 = Number(document.getElementById("nbr2").value);
             sum = nbr1 + nbr2;
             document.getElementById("sum").value = sum;
         }
      </script>
   </head>
   <body>
      <input id="nbr1"> + <input id="nbr2">
      <button onclick="sumOfNbr()">Calculate the sum</button>
      = <input id="sum">
   </body>
</html>
Result
+ =
[st_adsense] mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *