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
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
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
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
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
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…