Table of Contents
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.
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
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
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
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
After Clear data
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 using function
PHP subtraction of two numbers
PHP subtraction of two numbers using function
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.