addition

JavaScript Program to Add Two Numbers

JavaScript Program to Add Two Numbers

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

Addition

Sum of two numbers

JavaScript Sum of two numbers

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

 

JavaScript sum of two numbers using HTML

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

 

JavaScript Add two numbers using the form

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

 

Output2

 

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

 

PHP program to Addition of Two Numbers using function - PHP program
5 methods to add two numbers in Java
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago