Uncategorized

JavaScript Program for multiplying Two Numbers | 4 different ways

JavaScript Program for multiplying Two Numbers | 4 different ways

In this article, we will discuss the concept of the JavaScript Program for multiplying Two Numbers

In this post, we are going to learn how to write a program to find the multiplication of two numbers and display the result on the screen in JS language.

Code to find the multiplication  of two numbers in JS

Multiplication of two numbers in JS

In this program, the user initiates the values to variables f_Num and l_Num. The program calculates the multiplication of the given numbers using the multiplying(*) operator.

Program 1

// java script program to multiply of two numbers
const f_Num=6;
//declare and initaiize variable for f_Num
const l_Num=5;
//declare and initaiize variable for l_Num

//calculate product of given two numbers
const product=f_Num*l_Num;

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

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

The product of 6 and 5 is: 30

 

 

Multiplication of two numbers in JS using HTML

In this program, the user initiates the values to variables “firstNum” and “lastNum” and then the program calculates the multiplication of the given numbers using multiplying(*) operator inside the HTML tag

Program 2

<html>
<head>
<title>product of two numbers</title>
<script>
var fNumber=23;
var lNumber=5;
//Decare and initiaize variabes
var mul=fNumber*lNumber;
//Calculate multiplication of the given numbers 
//and assign the value to mul variable
document.write("Product of "+fNumber+" and "+lNumber+" is: "+mul);
//print result on the screen using mul variable
</script>
</head>
<body>

</body>
</html>

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

Product of 23 and 5 is: 115

 

 

Multiplication of two numbers in JS using function – #1

In this program, the user is asked to enter two numbers, The program calculates the multiplication of the given numbers using the function in JavaScript language.

Program 3

<html>
<head>
<title>product of two numbers</title>
<script>
function mul()//function to find product of given numbers
{
var fNum,lNum,product;
fNum=Number(document.getElementById("first").value);
sNum=Number(document.getElementById("second").value);
product=fNum*sNum;
document.getElementById("ans").innerHTML="Product:"+product;
}
</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

 

Output

 

Multiplication of two numbers in JS using function – #2

In this program, the user is asked to enter two numbers. The program calculates the multiplication of the given numbers using the function in JavaScript language, and then when the user click the “clear” button, entered fields are cleared.

Program 4

<html>
<head>
<title>product of two numbers</title>
<script>
function mul()//function to find product of given numbers
{
var fNum,lNum,product;
fNum=Number(document.getElementById("first").value);
sNum=Number(document.getElementById("second").value);
product=fNum*sNum;
document.getElementById("ans").innerHTML="Product:"+product;
}
function clr()//function to clear all fields
{
document.getElementById("first").value="";
document.getElementById("second").value="";
document.getElementById("ans").innerHTML="";
}
</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

After calculating product

Output 1

 

After Clear data

 

Output 2

Similar post

Java program to multiply two numbers

C++ program to multiply two numbers

C program to multiply two numbers

Python program to multiply two numbers

 

Java program to multiply two floating-point numbers

C++ program to multiply two floating-point numbers

C program to multiply two floating-point numbers

Python program to multiply two floating-point numbers

 

PHP addition of two numbers

PHP addition of two numbers using function

PHP subtraction of two numbers

PHP subtraction of two numbers using function

 

 

 

 

Karmehavannan

Recent Posts

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

1 year ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

1 year ago

This website uses cookies.