Ankaj Gupta
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
            

What to Try Next

  • Prompt the user for a number and limit, then print the table.
  • Render the results inside an HTML list or table instead of the console.
  • Use nested loops to build a full multiplication chart.
JavaScript Code

Join the discussion

Comments

0 comments

No comments yet — be the first to share your thoughts.

Related Posts