Currently, I am working on developing a program that can generate mathematical tables for any given number. For example:
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
To achieve this, the user should provide the following inputs:
(1) The number they want to create the table for (e.g., 3)
(2) Specify the starting point (e.g., 1)
(3) Specify the ending point (e.g., 4)
Below is the code snippet illustrating my current attempt:
function validateNumber(number){
while (isNaN(number) == true){
number = parseInt(prompt("Please enter a valid number","5"));
}
}
function mathTable (num, start, end){
for (var i=start; i<=end; i++){
var result = num*i;
document.write(num + " x " + i + " = " + result + "</br>");
}
}
var inputNum = parseInt(prompt("Enter the number you want the table for", "40"));
inputNum = validateNumber(inputNum);
var startPoint = parseInt(prompt("Enter the start point of the table", "1"));
startPoint = validateNumber(startPoint);
var endPoint = parseInt(prompt("Enter the end point of the table", "10"));
endPoint = validateNumber(endPoint);
mathTable(inputNum, startPoint, endPoint);