In this tutorial, we will discuss the title of the JavaScript Program to Add Two Numbers
In this topic, we are going to learn how to write a program to add two numbers in the JavaScript programming language
Program 1
Here, We use the plus(+) operator to find the sum of two numbers. The addition of two numbers 25 and 50 and the output is displayed here
const num_1=15; const num_2=12; //variable declaration //Addition of two numbers const sum=num_1+num_2; //display the result o sum console.log('The addition of '+num_1+' and '+num_2+' is: '+sum);
When the above code is executed, it produces the following result
The addition of 15 and 12 is: 27
Program 2
Here, We use the plus(+) operator to find the sum of two numbers. The addition of two numbers 10 and 20 and the output is displayed on a web page using HTML
<html> <head> <title>Add two numbers in Java script</title> <script> var fNum=10; var lNum=20; var sum=fNum+lNum; document.write("Sum: "+sum); </script> </head> <body> </body> </html>
When the above code is executed, it produces the following result
Sum: 30
Program 3
The program asks the user to enter two numbers using the form. then the result of the sum of two numbers is displayed when the user clicks the “add” button
<html> <head> <title>Add two numbers in Java script</title> <script> function add()//function definition { var fNum,sNum,sum; fNum=parseInt(document.getElementById("first").value); sNum=parseInt(document.getElementById("second").value); sum=fNum+sNum; document.getElementById("ans").value=sum; } </script> </head> <body> <p>Enter the first value:<input id="first"></p> <p>Enter the second value:<input id="second"></p> <button >When the above code is executed, it produces the following result
Similar post
Sum of two numbers in C language
Sum of two numbers in C++ language
Sum of two numbers in Python language
Sum of two numbers in Java language without + operator
Sum of two numbers in Java language using bitwise operator
Sum of two numbers in C language without + operator
Sum of two numbers in C language using bitwise operator
Calculate the addition of two numbers using the method in Java language
Calculate the addition of two numbers using a function in C language
Calculate the addition of two numbers using a function in C++ language
Calculate the addition of two numbers using a function in Python language
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…