M
Mark Scott
I have successfully written a function that writes out a times table as
follows:
var timesTable
parseFloat(timesTable)
var upperBound
parseFloat(upperBound)
function tableWriter()
{
var n
parseFloat(n)
for (n = 1; n < (upperBound+1)/10; n = n + 1)
{
document.write (n + " times "+ timesTable + " equals " + n * timesTable
+"<BR>")
}
}
timesTable = window.prompt ("What times table do you wish to see?")
upperBound = window.prompt ("how many entries do you need?")
tableWriter(timesTable);
However looking at the follwoing line:
for (n = 1; n < (upperBound+1)/10; n = n + 1)
if I had n < upperBound then I get 11 entries when I ask for 12 (fair
enough, zero based indexing)
If I had n < upperBound+1 then I get 120 entries (12 * 10? where is the *10
coming from?!)
I have had to bodge it using the code I have in the line now.
Any ideas why this is happening?
Regards
Mark
follows:
var timesTable
parseFloat(timesTable)
var upperBound
parseFloat(upperBound)
function tableWriter()
{
var n
parseFloat(n)
for (n = 1; n < (upperBound+1)/10; n = n + 1)
{
document.write (n + " times "+ timesTable + " equals " + n * timesTable
+"<BR>")
}
}
timesTable = window.prompt ("What times table do you wish to see?")
upperBound = window.prompt ("how many entries do you need?")
tableWriter(timesTable);
However looking at the follwoing line:
for (n = 1; n < (upperBound+1)/10; n = n + 1)
if I had n < upperBound then I get 11 entries when I ask for 12 (fair
enough, zero based indexing)
If I had n < upperBound+1 then I get 120 entries (12 * 10? where is the *10
coming from?!)
I have had to bodge it using the code I have in the line now.
Any ideas why this is happening?
Regards
Mark