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: