Programming Examples

Create a JavaScript function that displays the multiplication table of a number entered by the user.


Create a JavaScript function that displays the multiplication table of a number entered by the user.

Solution

<!DOCTYPE html>
<html>
<head>
    <title>Multiplication Table</title>
</head>
<body>

    <h2>Multiplication Table Generator</h2>
    <input type="number" id="num" placeholder="Enter a number">
    <button onclick="showTable()">Show Table</button>

    <div id="result"></div>

    <script>
        function showTable() {
            let n = document.getElementById("num").value;
            let output = "";

            for (let i = 1; i <= 10; i++) {
                output += n + " x " + i + " = " + (n * i) + "<br>";
            }

            document.getElementById("result").innerHTML = output;
        }
    </script>

</body>
</html>
▶ RUN

Output/ Explanation:

Latest Current Affairs 2026 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad