Agyan
adda
Run
Reset
Copy
JavaScript Tutorial › JS For Loop › Multiplication table
Back to tutorial
Code
Edit, then press Run or Ctrl+Enter
<input id="n" type="number" value="7" style="width:60px"> <button onclick="table()">Show table</button> <pre id="out"></pre> <script> function table() { const n = Number(document.getElementById('n').value); let text = ''; for (let i = 1; i <= 10; i++) { text += `${n} x ${i} = ${n * i}\n`; } document.getElementById('out').textContent = text; } table(); </script>
Result