I don't understand this code.
var timesTable;
while ((timesTable = prompt("Enter the times table", -1)) != -1) {.....}
Why is necessary to declare the variable before? I tried to do this:
while ((var timesTable = prompt("Enter the times table", -1)) != -1) {.....}
but it doesn't work. What's the problem? Is something about scope?
The full program is:
function writeTimesTable(timesTable, timesByStart, timesByEnd) {
for (; timesByStart <= timesByEnd; timesByStart++) {
document.write(timesTable + " * " + timesByStart + " = " + timesByStart * timesTable + "<br />");
}
}
var timesTable;
while ((timesTable = prompt("Enter the times table", -1)) != -1) {
while (isNaN(timesTable) == true) {
timesTable = prompt(timesTable + " is not a " + "valid number, please retry", -1);
}
document.write("<br />The " + timesTable + " times table<br />");
writeTimesTable(timesTable, 1, 12);
}
Thanks by advance.
