JavaScript Program to multiply of Two Numbers
JavaScript Program to multiply of Two Numbers
In this tutorial, we will discuss the title of the JavaScript Program to multiply of Two Numbers
In this topic, we are going to learn how to write a program to multiply of two numbers in the JavaScript programming language
Multiplication of two numbers
JavaScript program for multiplying two numbers
Program 1
Here, We use the multiplication(*) operator to find the product of the given two numbers.
The program calculates the product of the two numbers 7 and 5 , and the output is displayed here.
// JavaScript program to multiplication of two numbers const f_Num=7; //declare and initaiize variable for first num const l_Num=5; //declare and initaiize variable for second num //calculate multiplication of given two numbers const mul=f_Num*l_Num; //display the multiplication of two numbers console.log('The multiplication of '+f_Num+' and '+l_Num+' is: '+mul);
When the above code is executed, it produces the following result
The multiplication of 7 and 5 is: 35
JavaScript program for multiplying of two numbers using HTML
Program 2
Here, We use the multiplication(-) operator to find the product of two numbers. The program calculates the product of two numbers 32 and 20 then the output is displayed here using HTML
<html> <head> <title>multiplication of two numbers</title> <script> var firstNum=32; var lastNum=20;//Decare and initiaize variabes var mul=firstNum*lastNum;//Calculate multiplication of given numbers document.write("Multiplication of "+firstNum+" and "+lastNum+" is: "+mul); //print result on the screen </script> </head> <body> </body> </html>
When the above code is executed, it produces the following result
Multiplication of 32 and 20 is: 640
JavaScript program for multiplying of two numbers using function
Program 3
The program asks the user to enter two numbers using the form , then the result of the multiplication of two numbers is displayed when the user clicks the “multiply” button.
<html> <head> <title>Multiplication of two numbers</title> <script> function mul()//function to multiplication { var f_Num,l_Num,dif; f_Num=Number(document.getElementById("first").value); l_Num=Number(document.getElementById("second").value); multiply=f_Num*l_Num; document.getElementById("ans").innerHTML="Multiply:"+multiply; } </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 onclick="mul();">Multiply</button> <p id="ans"></p> </body> </html>
When the above code is executed, it produces the following result
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
Java program to multiply two numbers using methods
C program to multiply two numbers using function
C++ program to multiply two numbers using function
Python program to multiply two numbers function
PHP subtraction of two numbers
PHP addition of two numbers using function
PHP subtraction of two numbers using function