Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

JavaScript Program to Display Multiplication Table

Updated on Oct 30, 2024
By Mari Selvan
πŸ‘οΈ 792 - Views
⏳ 4 mins
πŸ’¬ 1 Comment
JavaScript Program to Display Multiplication Table

Photo Credit to CodeToFun

πŸ™‹ Introduction

Multiplication tables are fundamental in mathematics and play a crucial role in various programming applications. Creating a program to display the multiplication table for a fixed number is a common exercise for beginners in programming.

In this tutorial, we'll create a simple JavaScript program that displays the multiplication table for the fixed number 5.

πŸ“„ Example

Let's delve into the JavaScript code that accomplishes this task.

displayMultiplicationTable.js
Copied
Copy To Clipboard
// Function to display the multiplication table for the fixed number 5
function displayMultiplicationTable() {
  // Fixed multiplication factor
  const number = 5;

  console.log(`Multiplication Table for ${number}:`);

  // Iterate from 1 to 10 and display the result of multiplication
  for (let i = 1; i <= 10; ++i) {
    console.log(`${number} x ${i} = ${number * i}`);
  }
}

// Call the function to display the multiplication table
displayMultiplicationTable();

πŸ’» Testing the Program

Run the program, and it will display the multiplication table for the fixed number 5 from 1 to 10.

Output
Multiplication Table for 5:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

🧠 How the Program Works

  1. The program defines a function displayMultiplicationTable that displays the multiplication table for the fixed number 5 using a for loop.
  2. The fixed multiplication factor is declared using the const keyword.
  3. Inside the loop, the program logs the multiplication expression to the console.

🧐 Understanding the Concept of Multiplication Table

Multiplication tables are essential in mathematics and are often used in programming for various applications. This program provides a simple and effective way to display the multiplication table for a given number.

🎒 Optimizing the Program

While the provided program is straightforward, consider exploring and implementing alternative approaches or optimizations for displaying multiplication tables.

Feel free to incorporate and modify this code as needed for your specific use case. Happy coding!

πŸ‘¨β€πŸ’» Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
πŸ‘‹ Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mari Selvan
Mari Selvan
10 months ago

If you have any doubts regarding this article (JavaScript Program to Display Multiplication Table), please comment here. I will help you immediately.

We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy