Wrox Programmer Forums
|
BOOK: Beginning JavaScript
This is the forum to discuss the Wrox book Beginning JavaScript by Paul Wilton; ISBN: 9780764544057
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 18th, 2003, 11:57 AM
Authorized User
 
Join Date: Jun 2003
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default script from book not working

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>
 
Old November 18th, 2003, 01:46 PM
Authorized User
 
Join Date: Nov 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old November 18th, 2003, 01:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old November 18th, 2003, 01:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You see, I took so long to spot it someone else beat me to it :D
 
Old November 18th, 2003, 01:56 PM
Authorized User
 
Join Date: Nov 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by pgtips
 You see, I took so long to spot it someone else beat me to it :D
And a rookie at that !!! :D






Similar Threads
Thread Thread Starter Forum Replies Last Post
IE7 script not working on linux server luminus BOOK: CSS Instant Results 9 February 1st, 2016 07:35 AM
script not working in mozilla, but works in IE grobar Javascript 1 April 9th, 2008 03:51 AM
Client Side Script Not Working sramesh ASP.NET 2.0 Basics 3 August 2nd, 2007 03:56 PM
script not working in mozilla but works in IE grobar Javascript How-To 0 May 26th, 2005 06:19 PM
vb script is not working apry BOOK: Beginning ASP.NET 1.0 5 April 28th, 2004 05:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.