Skip to content

Write a JavaScript program that calculates the product of two numbers and returns the result

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:

JavaScript program calculates product of two numbers and returns result

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

2 thoughts on “Write a JavaScript program that calculates the product of two numbers and returns the result”

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading