我一直在試圖有一個簡單的乘法表程序重複,直到輸入「-1」。我嘗試了幾個循環的不同變體,但是我獲得的最成功只是重複提示問題。該代碼的工作原理,直到我試圖重複它。以下代碼是作爲一次性運行程序的工作版本。任何幫助讚賞。自動重複JavaScript功能在瀏覽器中,直到終止輸入輸入
function getVariables(){
var table = parseInt(prompt("Enter table: "));
var start = parseInt(prompt("Enter start: "));
var end = parseInt(prompt("Enter end: "));
if (isNaN(table) || isNaN(start) || isNaN(end)) {
alert("Please enter numerical integers only");
getVariables();
}
else {
timesTable(table, start, end);
}
}
function timesTable(table, start, end) {
for (;start <= end; start++) {
document.write(table + " * " + start + " = " + table * start + "<br/>");
}
}
var proceed = prompt("Do you want to display times tables? Press 'ENTER' to continue or enter '-1' to exit.");
if (proceed != -1){
getVariables();
}
https://developer.mozilla.org/en-US/docs/Web/API/document.write – Teemu