PUBLISHED ON: MARCH 14, 2023
JavaScript Program to Display the Multiplication Table of a Number
A multiplication table is a grid that shows what happens when you multiply two or more numbers together. Multiplication tables are a common way to teach kids how to multiply and an important way to learn and understand basic math.
In this project, we will make a JavaScript program that shows the multiplication table for a given number. We will use different parts of the JavaScript programming language, such as loops and string concatenation, to make a program that is fast, accurate, and easy to understand. We also have an interactive JavaScript course where you can learn JavaScript from basics to advanced and get certified. Check out the course and learn more from here.
Program to Display the Multiplication Table of a Number
/* JavaScript program to generate a multiplication table of a particular range */
var num = parseInt(prompt('Enter an integer: '));
var range = parseInt(prompt('Enter a range: '));
//creating a multiplication table
for(let i = 1; i <= range; i++) {
var res = i * num;
console.log(num +" * "+ i + " = " + res);
}
?
Enter an integer: 3
Enter a range:8
3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
3 * 4 = 12
3 * 5 = 15
3 * 6 = 18
3 * 7 = 21
3 * 8 = 24
Conclusion
In conclusion, the JavaScript program developed to display the multiplication table of a given number has proven to be a useful and effective tool for learning and practicing multiplication. The program utilizes a loop to iterate through the range of integers from 1 to 10 and calculates the products of the input number multiplied by each of those integers. The resulting products are then displayed in a table format, making it easy to visualize and understand the relationship between the input number and the products.