Subject: script from book not working
Posted By: whyulil Post Date: 11/18/2003 10:57:50 AM
i cant see where im going wrong. The code is supposed to produce the times table based on the values at the end of the script:
writeTimesTable(4,4,9)

However it only writes
4 * 10 = 40

Can anybody spot my mistake? ive gone over it 5 times and i cant see the mistake.

<html>
<body>
<script language="JavaScript">
function writeTimesTable(timesTable, timesByStart, timesByEnd)
{
    for (; timesByStart <= timesByEnd; timesByStart++);
    {
            document.write(timesTable + " * " + timesByStart + " = " + timesByStart * timesTable + "<br>");
    }
}

writeTimesTable(4,4,9);
</script>
</body>
</html>
Reply By: JayinOC Reply Date: 11/18/2003 12:46:21 PM
I think I found it.

 for (; timesByStart <= timesByEnd; timesByStart++);

is the line that is screwing you up. I had no idea it would cause JS to mess up but the " ; " you have after the function parameters is what is doing it. Take out the semicolon from that line and you should be good to go.

I am totally new to Java Script and these chapter 3 examples nearly made me want to jump off the roof. This stuff is pretty hard for me.

Reply By: pgtips Reply Date: 11/18/2003 12:50:51 PM
You had me going for a while here .

Remove the ; from the end of this line
for (; timesByStart <= timesByEnd; timesByStart++);
otherwise you're closing the loop and the rest of the code is only executed once after the loop finishes.

hth
Phil
Reply By: pgtips Reply Date: 11/18/2003 12:53:01 PM
You see, I took so long to spot it someone else beat me to it
Reply By: JayinOC Reply Date: 11/18/2003 12:56:57 PM
quote:
Originally posted by pgtips

You see, I took so long to spot it someone else beat me to it



And a rookie at that !!!


Go to topic 5141

Return to index page 1002
Return to index page 1001
Return to index page 1000
Return to index page 999
Return to index page 998
Return to index page 997
Return to index page 996
Return to index page 995
Return to index page 994
Return to index page 993