This is a simple JavaScript program that generates a multiplication table for a given number up to 20.
- Run the JavaScript code in a web browser.
- You will be prompted to enter a number.
- The program will then display a multiplication table for the entered number up to 20.
If you enter the number 5, the program will display:
- 5 * 1 = 5
- 5 * 2 = 10
- 5 * 3 = 15 ...
- 5 * 20 = 100
- The prompt function is used to ask the user to enter a number. The message "Hello, I'm The Calculation Robot\nEnter a number you want to calculate:" is displayed to the user. The entered number is stored in the number constant.
const number = prompt(
"Hello, I'm The Calculation Robot\nEnter a number you want to calculate:"
);
- An empty string result is initialized to store the multiplication table.
let result = "";
- A for loop is used to iterate from 1 to 20. In each iteration, the current number (factor) is multiplied with the user-entered number (number), and the result is appended to the result string along with the current multiplication operation.
for (let factor = 1; factor <= 20; factor++) {
result += " -> " + number + " * " + factor + " = " + number * factor + "\n";
}
- Finally, an alert is used to display the multiplication table. The message includes the user-entered number and the calculated results.
alert("The result of multiplying the number " + number + "\n\n" + result);
In summary, this code is a simple way to generate a multiplication table for a given number in JavaScript. It uses a for loop to iterate over a range of numbers, performs multiplication in each iteration, and stores the results in a string that is then displayed to the user
Clone the repository to your local machine.
git clone https://github.com/usuariodaniel/JavaScript-Multiplication-Table-Generator.git
Open the robot.html
file in your web browser.
Follow the prompt to enter a number.
Contributions to this project are welcome. If you would like to contribute, please follow these steps:
- Fork this repository.
- Create a branch with a descriptive name for your change.
- Make your changes to the created branch.
- Submit a pull request to the master branch of this repository.
If you have any questions or suggestions, please contact me via my email or my GitHub profile.
This project was made possible thanks to the support and guidance of OneBitCode
This project was inspired by a OneBitCode challenge