Calculations

JavaScript Program to substract Two Numbers

JavaScript Program to substract Two Numbers

In this tutorial, we will discuss the title of the JavaScript Program to substract Two Numbers

In this topic, we are going to learn how  to write a program to subtract two numbers in the JavaScript programming language

Subtract of two numbers

Subtraction

JavaScript program for subtracting of two numbers

Program 1

Here, We use the minus(-) operator to find the differences between the given two numbers. The difference between the two numbers 24 and 14 and the output is displayed here

//Caculate subtraction of two numbers in JavaScript

const f_Num=24;
const l_Num=14;
//declare and initaiize two variable

//calculate difference of two numbers
const dif=f_Num-l_Num;

//display the difference of two numbers
console.log('The subtraction of '+f_Num+' and '+l_Num+' is: '+dif);

When the above code is executed, it produces the following result

The subtraction of 24 and 14 is: 10

 

JavaScript program for subtracting of two numbers using HTML

Program 2

Here, We use the minus(-) operator to find the differences between two numbers. The difference between two numbers 15 and 20 , the output is displayed here

<html>
<head>
<title>Subtraction of two numbers</title>
<script>
var f_Num=15;
var l_Num=20;
var sub=f_Num-l_Num;
document.write("subtraction of "+f_Num+" and "+l_Num+" is: "+sub);
</script>
</head>
<body>

</body>
</html>

When the above code is executed, it produces the following result

subtraction of 15 and 20 is: -5

 

JavaScript program for subtracting of two numbers using function

Program 3

The program asks the user to enter two numbers using the form and, then result of the difference between two numbers is displayed when the user clicks the “subtract” button

<html>
<head>
<title>subtract two numbers</title>
<script>
function subs()//function to subtraction
{
var f_Num,s_Num,dif;
f_Num=Number(document.getElementById("first").value);
s_Num=Number(document.getElementById("second").value);
dif=f_Num-s_Num;
document.getElementById("ans").innerHTML="Difference:"+dif;
}
</script>
</head>
<body>
<p>Enter the first Number:<input type="text" id="first"></p>
<p>Enter the second Number:<input type="text" id="second"></p>
<button >

When the above code is executed, it produces the following result

Subtract two number

Suggested for you

Subtraction of two numbers in Java language

Subtraction of two numbers in C Language

Subtraction of two numbers in C++ Language

Subtraction of two numbers in Python Language

 

Subtraction of two numbers using method in Java language

Subtraction of two numbers using function in C Language

Subtraction of two numbers using function in C++ Language

Subtraction of two numbers using function in Python Language

Subtraction of two numbers using C# language

Subtraction of two numbers using function in C# language

JavaScript program to addition of two numbers

JavaScript program for adding of two numbers|4 ways

PHP program to add two numbers

PHP program to add two numbers using unction

PHP program to divide two numbers using function
JavaScript: Calculate division of Two Numbers
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

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

3 days ago

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