August 15, 2020
Print table using javascript
JavaScript Practice
Program to Print a Multiplication Table
Printing a multiplication table is a classic beginner exercise. This example uses a simple for loop coupled with template literals to generate readable output for any number.
const number = 5;
const limit = 10;
for (let i = 1; i <= limit; i += 1) {
const result = number * i;
console.log(`${number} × ${i} = ${result}`);
}
Tip: Wrap this logic in a function for reusability, or accept number and limit from form inputs.
Sample Console Output
5 × 1 = 5
5 × 2 = 10
5 × 3 = 15
5 × 4 = 20
5 × 5 = 25
5 × 6 = 30
5 × 7 = 35
5 × 8 = 40
5 × 9 = 45
5 × 10 = 50
JavaScript Code