In this tutorial you will learn with an example where the user clicks the button after entering the number in their respective text boxes, the result will get displayed through the alert box. It’s a very easy JavaScript Example code of calculates the product of two numbers and returns the result.
JavaScript example of calculating multiplication for 2 numbers
HTML example code:-
<!DOCTYPE html>
<html>
<body>
<form>
1st Number : <input type="text" id="fnum" /><br>
2nd Number: <input type="text" id="snum" /><br>
<input type="button" onClick="multiplyBy()" Value="Multiply" />
</form>
<p>Product of two numbers is : <br>
<span id = "result"></span>
</p>
<script type="text/javascript">
function multiplyBy()
{
num1 = document.getElementById("fnum").value;
num2 = document.getElementById("snum").value;
document.getElementById("result").innerHTML = num1 * num2;
}
</script>
</body>
</html>
Output:
Do comment if you have any doubts and suggestion on this topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version
How to use the mutiply fuction result to multiply with another number.
const multiply = (num1, num2) => {
return num1 * num2;
};
let resulMultiply = multiply(4, 5);
console.log(resulMultiply * number);