Javascript Program to print Multiplication table of a given number


In this post, let's learn how to print multiplication table of a given number.

Javascript program to generate multiplication table:

let num = 16;

for (let i=1; i<=10; i++){
console.log(num + " * " + i + " = " + num*i);  
}

Result

16 * 1 = 16 
16 * 2 = 32 
16 * 3 = 48 
16 * 4 = 64 
16 * 5 = 80 
16 * 6 = 96 
16 * 7 = 112 
16 * 8 = 128 
16 * 9 = 144 
16 * 10 = 160

If you want to generate the multiplication table to other range like 20, provide i<=20 in the for loop condition which generates the output as below.

16 * 1 = 16 
16 * 2 = 32 
16 * 3 = 48 
16 * 4 = 64 
16 * 5 = 80 
16 * 6 = 96 
16 * 7 = 112 
16 * 8 = 128 
16 * 9 = 144 
16 * 10 = 160 
16 * 11 = 176 
16 * 12 = 192 
16 * 13 = 208 
16 * 14 = 224 
16 * 15 = 240 
16 * 16 = 256 
16 * 17 = 272 
16 * 18 = 288 
16 * 19 = 304 
16 * 20 = 320

Try yourself here.