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>
Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad