Multiplication and Division of Two Numbers Using JavaScript Or Jquery

Friends, today I will tell you through experts php. That how you can multiply and divide two numbers by javascript. So let’s try to understand.

Friends, you can create multiplication and division calculator in very easy way by javascript. I will tell you very easy way. You have to first create a function in javascript. You can name that function in your own way. Then you have to take two variables in the same function in which you can get the value through id. Then you have to multiply or divide both those variables by taking another variable. And then you will get your answer.

create multiplication and division calculator by javascript, create division and multiplication two number calculator using javascript with html, css

Let me explain to you by doing practical.

Overview

Step 1:- Create html file for multiplication and division calculator.

Step 2:- Add JavaScript Code in this file.

 

Step 1:- Create html file for multiplication and division calculator.

 

First you create a form of multiplication and division. Then Add 2 button multiply and divide in it.

multiplication-division-calculate.html

<!DOCTYPE html>
<html> 
<head>
<meta charset=utf-8 />
<title>Multiplication and Division of Two Numbers Using JavaScript Or Jquery</title>
<style>
body {margin: 30px;}
</style> 
</head>
<body>
<h1>Multiplication and Division of Two Numbers Using JavaScript Or Jquery</h1>
<form>
1st Number : <input type="text" id="firstNumber" /><br>
2nd Number: <input type="text" id="secondNumber" /><br>
<input type="button" onClick="multiply()" Value="Multiply" />
<input type="button" onClick="divide()" Value="Divide" />
</form>
<b>The Result is : <br>
<span id="answer"></span>
</b>
</body>
</html>

 

Step 2:- Add JavaScript Code in this file.

 

Then add the multiplication and division code of javascript in this form.

<script>
function multiply()
{
number1 = document.getElementById("firstNumber").value;
number2 = document.getElementById("secondNumber").value;
document.getElementById("answer").innerHTML = number1 * number2;
}
function divide() 
{ 
number1 = document.getElementById("firstNumber").value;
number2 = document.getElementById("secondNumber").value;
document.getElementById("answer").innerHTML = number1 / number2;
}
</script>

Now you have been given the complete code below to manage it correctly. Also along with the link to the demo, you can copy and paste this code in your file and run it on your server.

multiplication-division-calculate.html

<!DOCTYPE html>
<html> 
<head>
<meta charset=utf-8 />
<title>Multiplication and Division of Two Numbers Using JavaScript Or Jquery</title>
<style>
body {margin: 30px;}
</style> 
</head>
<body>
<h1>Multiplication and Division of Two Numbers Using JavaScript Or Jquery</h1>
<form>
1st Number : <input type="text" id="firstNumber" /><br>
2nd Number: <input type="text" id="secondNumber" /><br>
<input type="button" onClick="multiply()" Value="Multiply" />
<input type="button" onClick="divide()" Value="Divide" />
</form>
<b>The Result is : <br>
<span id="answer"></span>
</b>
<script>
function multiply()
{
number1 = document.getElementById("firstNumber").value;
number2 = document.getElementById("secondNumber").value;
document.getElementById("answer").innerHTML = number1 * number2;
}
function divide() 
{ 
number1 = document.getElementById("firstNumber").value;
number2 = document.getElementById("secondNumber").value;
document.getElementById("answer").innerHTML = number1 / number2;
}
</script>
</body>
</html>