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

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago