Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 27th, 2004, 08:40 AM
Authorized User
 
Join Date: Sep 2003
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default problems with examples in book

this is the code for exercise 3 chap 4 in beginning javascript. I keep getting an error when I run it and need help solving.

<html>
<head>
<script language=javascript>
function fix(fixNumber, decimalPlaces)
{
var div = Math.pow(10, decimalPlaces);
fixNumber = new String(Math.round(fixNumber * div) / div);

If (fixNumber.lastIndexOf(".") == -1)
{
fixNumber = fixNumber + ".";
}
var zerosRequired = decimalPlaces - (fixNumber.length - fixNumber.lastIndexOf(".") -1);


for (zerosRequired = 0; zerosRequired > 0; zerosRequired--)
{
fixNumber = fixNumber + "0";
}
return fixNumber;
}
</script>
</head>
<body>
<script language=javascript>
var number1 = prompt("enter a number","");
var number2 = prompt("enter number of decimal places","");

document.write(number1 + " fixed to " + number2 + " decimal places is: ");
document.write(fix(number1,number2));
</script>
</body>
</html>

Reply With Quote
  #2 (permalink)  
Old May 27th, 2004, 08:45 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi skicrud,

The line:

If (fixNumber.lastIndexOf(".") == -1)

should start with "if" (all lowercase).

HTH,

Chris

Reply With Quote
  #3 (permalink)  
Old May 27th, 2004, 08:52 AM
Authorized User
 
Join Date: Sep 2003
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks, I wish WROX would be more carefull in their beginner books

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference in book and examples golf1052 BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 1 June 15th, 2007 04:14 PM
Problems with Examples of Beginning with php4 Book xtimox Beginning PHP 2 December 17th, 2004 02:01 PM
Problems with the examples from the J2EE book alf.guzman J2EE 0 April 20th, 2004 09:43 AM
Book examples duff? Vormulac ASP.NET 1.0 and 1.1 Basics 2 September 8th, 2003 04:37 AM
Book Examples luisfco Pro VB 6 1 September 5th, 2003 06:50 PM



All times are GMT -4. The time now is 08:01 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.