Head First JavaScript

Errata for Head First JavaScript

Submit your own errata for this product.


The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.


Color Key: Serious Technical Mistake Minor Technical Mistake Language or formatting error Typo Question Note Update



Version Location Description Submitted By Date Submitted
Printed Page 437
Second colum first answer

The book suggests that "You can just think of the floor() method as always chopping off the decimal part", but that's only true for positive numbers. For negative non-integer ones the result is one less then the "chopped" value.

KJB  Aug 12, 2013 
Printed Page 432
Second column second question

The answer suggests to pass the previous search index into the indexOf() method to continue searchnig through a string, but that's not correct. You should pass the previous search index + 1 otherwise the function will return the same index again.

KJB  Aug 12, 2013 
Printed Page 432
Second column first question

charAt() function does not search for a single character as the answer suggests, but simply return the character at the given location.

KJB  Aug 12, 2013 
Safari Books Online 10
United States

On page 9 the sharpen your pencil activity the last one circled isn't the same as the answers given on page 10.

Anonymous  Jul 11, 2013 
PDF Page 47
Right sidebar

Chapter 1 page 14 Exercise Solution. Description of "value" listed as "the current value of the ZIP field" but the arrow is pointing to this.value in input id="bedrooms" div

Anonymous  Apr 03, 2013 
PDF Page 330
330page, Bullet Points--the last one!

The last one Bullet Points: it says The test () method in the RegExp object is used to a test a regular expression pattern on a string of text. s/b The test () method in the RegExp object is used to test a regular expression pattern on a string of text.

sufei  Mar 06, 2013 
PDF Page 198
2nd paragraph

"Numeric keys are known a indexes..." should be "Numeric keys are known as indices..."

Anonymous  Dec 10, 2012 
PDF Page 177
1st paragraph & side statement

In paragraph: the switch/case statement allows you to more efficiently choose between any number of things. Should be: the switch/case statement allows you to more efficiently choose among any number of things. In side statement: the switch/case statement efficiently chooses between more than two things. Should be: the switch/case statement efficiently chooses among more than two things.

Anonymous  Dec 07, 2012 
Printed Page 127-128
127 sharpen your pencil 128 syp soluion

the variable userName is not declared in this code. Within the greetUser() is the place to do it. Re-work things, this way: function greetUser { var userName; if (navigator.cookieEnabled) userName = readCookie("irock_username"); ... rest of greetUser is fine .... }

Douglas Hemmick  Oct 15, 2012 
Printed Page 122-123
122 Code way up close; 123 System behavior after coding

I can't tell what happened when Bill Slaughter tried to run the script, as he notes in his page 123 errata. However, I can say that the page 122 addition to the touchRock() function suggested by anonymous IS needed. I.e., that addition (add the readCookie line of code) is necessary for functioning, but may not be sufficient for what ails Bill S.

Douglas Hemmick  Oct 15, 2012 
Printed Page 102-105
102 whole page 103 bottom, 104 top, 105 bottom

on seeing the errata posted by another user here I find that my won errata posted here may be in error! another errata-posted states that you can correct the code in the "sharpen your pencil" on page 104 by letting your resizeRock() function contain this line: document.getElementById("rockImg").style.height = ((document.documentElement.clientHeight - 100)*0.9) + "px" I tried his suggestion and it works for me as well. I.e., my own correction of omitting the "style" element from getElementById is NOT needed ( and indeed does not work as well as ) the above suggestion. My errata was not quite right, and has been corrected!

Anonymous  Oct 15, 2012 
Printed Page 102-105
102, whole page 103 bottom 104 top, 105 bottom

The command to access the height of the rock simply does not work, and I have tried it in both google chrome and internet explorer. Rather, if you *remove* the object reference "style" you will do fine. I.e.: WRONG "getElementById("rockImg").style.height" RIGHT "getElementById("rockImg").height" I can't explain what is going on, but simply report the results of my (frustrating!) Sunday evening trying to find out why the hell the thing was not working...

Anonymous  Oct 15, 2012 
Printed Page 96
Nederland

In the Sharpen your pencil Solution the text "The five-minute delay is calculated in milliseconds by first converting to minutes (x60) and then to milliseconds (x1000)" should be "The five-minute delay is calculated in milliseconds by first converting to seconds (x60) and then to milliseconds (x1000)"

Wim 't Jong  Aug 30, 2012 
PDF Page 299
4th paragraph

"you're name is onchange" should be "your name is onchange"

Anonymous  Feb 20, 2012 
PDF Page 61
2nd paragraph

Stray apostrophe: "but it's purpose is" should read "but its purpose is"

Anonymous  Feb 06, 2012 
Printed Page 433
Sharpen Your Pencil Solution at top of page, plus code samples

The Sharpen Your Pencil solution and the later code samples on the page refer to "blog1" and "blog2". This is inconsistent with the code in the actual application, and I believe it is an error. Both of those should be in the blog array, so the numbers should be in square brackets - that is, they should be "blog[1]" and "blog[2]". Unless we're dealing with hypothetical separate blog objects that art different from the way we've been coding this blog, in which case it's just confusing.

mycranium  Oct 29, 2011 
Printed Page 273
Code example after first paragraph

The code sample shows an alert, whose content is the value of the myShowSeatStatus() function. alert(myShowSeatStatus(23)); However, the code in that function, (which is a reference to showSeatStatus()), does nothing but generate an alert. So the example generates an alert, the content of which is anoterh alert (generated by the function called within the alert). It would make sense if showSeatStatus() simply assembled the text string to be displayed in the alert, but that's not what it is. It's not part of the codebase for the projects in the book so it's not going to mess up any readers' code, but it is confusing and I don't think it's correct.

mycranium  Oct 29, 2011 
Printed Page 442
the code exerpt

in the this.containsText function literal, the return function has one too many open parens

Matthew  Sep 26, 2011 
Printed Page 324
What's My Purpose answer box

The expression metacharacters all have lines drawn to their correct meanings, but the order of the 2nd and 6th answers have been reversed from the previous page. In other words, you've reversed the order of the sentences "The sub-pattern is optional..." and "The subpattern is required..."

Frank Serkland  Sep 18, 2011 
PDF Page 477
2nd paragraph

Missing function arguments do not become null. Instead they are undefined.

Anonymous  Jul 30, 2011 
PDF Page 379
Bullet points at the top of the page

display:none and display:block are offered as an alternative to visible. But as the buttons are arranged in a single row, display:inline rather than display:block might be more appropriate. Arguably, it would be better to use the display rather than the visibility style for Stick Figure Adventure, as the hidden button should be treated as not existing. Otherwise the remaining (single) button isn't centered exactly.

Anonymous  Jul 04, 2011 
Printed Page 234
code box

"The alert messages have reversed the usage of variables i & j - should be like "Seat " + j + " in row " + i + " is available."" Following on to this, if we wish to maintain the format of the previous example of this type from page 208, we should also add one to seat and row number so there is no "Row 0" or "Seat 0". Thus: alert("Seat " + (j+1) + " in row " + (i+1) + " is available.");

Douglas Calhoun  Jul 03, 2011 
Printed Page 266
Chapter 6 where there is an exercise solution

If you turn to page 266 in Chapter 6 where there is an exercise solution. There is a part of the code that has been incorrectly crossed out. See below for what is in the text book: Msg += "Global"; // "Local"; (the comment says "The intended text was commented out to keep it out of the message") It appears the wrong part was crossed out. It should have been everything after the // that needs to be crossed out: Msg += "Global"; // "Local"; (like this)

Anonymous  Jun 01, 2011 
Printed Page 279
Sample code

The illustration referes to seat 23, but the code example refers to seat 26. Change "seat26" to "seat23". Change showSeatStatus(26) to showSeatStatus(23).

Bob Verhey  Apr 27, 2011 
Printed Page 277
Each reference to showSeatStatus

The seat referenced in the illustation is actually seat number 23. Text located center right on page: Change "showSeatStatus(26);" to "showSeatStatus(23);". In code sample: Change <img id="seat26" src="" alt="" onclick="showSeatStatus(26);" /> to <img id="seat23" src="" alt="" onclick="showSeatStatus(23);" />

Bob Verhey  Apr 27, 2011 
Printed, PDF Page 274
Exercise Solution

Solution reads: x = 12 y = doThat z = doThat(12) = 11 x = doThat(11) = 10 y = 10 alert(doThat(11 - 10)) Should read: x = 11 y = doThat z = doThat(11) = 11 x = doThat(11) = 11 y = 11 alert(doThat(11 - 11)) both the increment and the decrement are POST, so increment and decrement happen after the value is returned, but scope of num is inside the method, so incremented and decremented num values are never seen outside of doThis(num) and doThat(num) methods.

Anonymous  Apr 16, 2011 
Safari Books Online 106
Top of page

The question at the top of the page reads "Doesn't the Rock Image stay the same size?" The response as written, is "No, the rock size isn't dynamic." It should read, Yes, the Rock imsge does stay the same size because the size is not dynmamic. If the question that was posed was "Doesnt' the Rock image change its size", then the existing response would be correct.

Anonymous  Apr 05, 2011 
Printed Page 234
Sharpen your pencil Solution

The alert messages have reversed the usage of variables i & j - should be like "Seat " + j + " in row " + i + " is available."

Anonymous  Feb 15, 2011 
PDF Page 347
First sentence of the page

The first sentence is an incomplete sentence... "The getElementById() method of the standard document object that we've used quite a lot." Perhaps it should read: "We have used the getElementById() method of the standard document object quite a lot."

robbiego  Jan 16, 2011 
PDF Page 329
top of page, first Answer

About 2/3 through the answer, "then" is used when "than" should be used: "If no data has been entered, a different message is displayed then if an invalid date has been entered." s/b "If no data has been entered, a different message is displayed than if an invalid date has been entered."

robbiego  Jan 14, 2011 
PDF Page 234
middle of the solution code

Both alert statements have the "seat" and "row" variables swapped. It appears: alert("Seat "+i+" in row "+j+" is available."); It should be: alert("Seat "+j+" in row "+i+" is available."); Same error is in the "unavailable" alert statement.

robbiego  Jan 09, 2011 
PDF Page 182
middle of the solution code

there is a semi-colon missing after the curScene = 2 in the middle of the solution code.

robbiego  Jan 08, 2011 
PDF Page 182
middle of sample code

there is a semi-colon missing after the curScene = 2 in the middle of the sample code.

robbiego  Jan 08, 2011 
PDF Page 181
middle of sample code

there is a semi-colon missing after the curScene = 2 in the middle of the sample code.

robbiego  Jan 08, 2011 
Printed Page 125
Second word of the first answer.

The way the sentence is written: "But the hard disk is where the vast majority of browsers store cookies, not all browsers have access to the hard disk." makes it a run-on sentence. It can be revised by changing "But" to "Although". "Although the hard disk is where the vast majority of browsers store cookies, not all browsers have access to it."

Thomas Frank  Dec 29, 2010 
Printed Page 49
Large text blurb on right side of page

the apostrophes need to be removed from the words "variable's" and "constant's" Apostrophes imply ownership; they do not make a word plural.

Thomas Frank  Dec 28, 2010 
Printed Page 104
Sharpen your pencil Solution

I couldn't get the resizeRock code to work as it was written with either Safari or Chrome on Mac OS X. In the end here's what worked. document.getElementById("rockImg").style.height = ((document.documentElement.clientHeight - 100) * 0.9) + "px"; i.e. I had to use "document.documentElement.clientHeight" instead of "document.body.clientHeight" to get the correct size of the client window of the browser. and the addition of + "px" at the end to make the image actually resize.

Anonymous  Dec 25, 2010 
PDF Page 237
mandango.html source code

Extra "<" exists in div tag. <<div style="margin-top:25px; text-align:center"> should be <div style="margin-top:25px; text-align:center">

Yasuo Honda  Dec 05, 2010 
Printed Page 449
First paragraph, first sentence

"If it was only that easy" should be "If it were only that easy".

Thomas Kennedy  Aug 05, 2010 
Printed Page 332
paragraph beginning "Howard's idea"

"reign in" should be "rein in".

Anonymous  Aug 04, 2010 
Safari Books Online 54
End of the page (Magnets)

You mention that "alarm_status" is an illegal Javascript name. But, isn't it legal? Thanks.

Abder-Rahman  Jul 22, 2010 
Safari Books Online 46
Last paragraph

Instead of using number like 0.925,... I think "a" has to come before "number". Thanks.

Abder-Rahman  Jul 22, 2010 
Safari Books Online 26
Last onclick in the code snippet

onclick:= It has a colon ":" after onclick. Shouldn't it be removed? Thanks.

Abder-Rahman  Jul 22, 2010 
Safari Books Online 15
Left side beside the phone speaker

"Irate" beta Is there a typo here with "I"? Thanks.

Abder-Rahman  Jul 22, 2010 
Safari Books Online 11
Last question

<head> of I think there is EXTRA space after <head> Thanks.

Abder-Rahman  Jul 22, 2010 
Safari Books Online 6
Last paragraph

",JavaScript" code often resides right there in the web page. Shouldn't there be a space after the comma? Thanks.

Abder-Rahman  Jul 22, 2010 
Printed Page 71
second sentence

The word "to" appears twice in the second sentence on page 71. "The key to to accessing a web page element..." should say "The key to accessing a web page element..."

dancro  May 22, 2010 
Printed Page 314
top paragraph

form["zipcode_help"],form["message_help"],....... are not working because we can only use form[] for selecting form fields. Here zipcode_help and message_help are span elements. So this generate error. You can use document.getElementById("zipcode_help") instead of that.

Abhilash.M.A  May 10, 2010 
PDF Page 282
Comment in "Sharpen your pencil" exercise

The comment "The onlick property for each seat image is accessed to set onclick event handlers" should say "onclick" not "onlick". This typo gets funnier every time I see it!

Jim Tough  Apr 18, 2010 
PDF Page 279
First paragraph

The sentence "The onlick event for seat images in Mandango" should say "onclick" not "onlick". The typo is funny, yet incorrect.

Jim Tough  Apr 18, 2010 
Printed Page 569
First if-statement within handleRequest's code listing

When running the example directly from my computer (i.e. opening youcube13.html directly in my browser), the page shows the initial body components and the image wait.gif and never proceeds. I was able to debug this and noticed that within handleRequest, ajaxReq.getStatus() is 0 (zero) rather than the expected 200 (HTTP's OK). I suspect it is due to the difference between the file:/// protocol and the HTTP:// protocol. To get the example to work, change handleRequest()'s first if-statement test to: if (ajaxReq.getReadyState() == 4 && ((ajaxReq.getStatus() == 200) || (ajaxReq.getStatus() == 0))) {

Daniel Roy  Mar 28, 2010 
Printed Page 96
Sharpen your Pencil Solution top of the page

The mistake is found on page 96 in the printed and the electronic downloaded versions. One of the notes in the Sharpen your Pencil Solution, bottom left corner of the box at the top of the page. The five-minute delay is calculated in milliseconds by first converting to minutes (x60) and then to milliseconds (x1000). should be: The five-minute delay is calculated in milliseconds by first converting to seconds (x60) and then to milliseconds (x1000).

stosss  Mar 16, 2010 
Printed Page 429
JavaScript Magnets and Solution

The code in both the problem and solution compare the length of the blog to the variable i. The code would not work since the variable is out of scope at this point, because it was declared as part of the for loop.

Nathan Warner  Feb 09, 2010 
Printed Page 568
top

Not sure if this has been mentioned(just joined forum). Looking at the 'youcube13.html' code. Do we need this code?: // Set the blog-wide signature Blog.prototype.signature = "by Puzzler Ruby"; Since we have added this code: // Set the blog-wide signature Blog.prototype.signature = "by " + getText(xmlData.getElementsByTagName("author")[0]); We only need to extract the author's name from the 'blog.xml' file now(right?). Jeff

Jeffrey Yee  Nov 05, 2009 
Printed Page 384
2nd paragraph?

I think this line on page 384 of H.F. java script: decisionElem.appendChild("Decision 1 -> Scene 1 : Fork in the road.")); should be: decisionElem.appendChild(document.createTextNode("Decision 1 -> Scene 1 : Fork in the road.")); The line in the book throws a "type mismatch" error.

Anonymous  Oct 31, 2009 
Printed Page 59,73
Definition of placeOrder function

The placeOrder function takes an HTML form as an argument, but the placeOrder() declaration is missing the "form" should be: placeOrder(form) this mistake is on at least page 59, and 73, in the code samples included in the download, the code is correct.

Robert Porter  Oct 20, 2009 
Printed Page 78
Code snippets between the arrows

parseInt("18") and parseInt("3 dozen") should be parseDonuts("18") and parseDonuts("3 dozen")

Kevin Sikes  Aug 29, 2009 
Printed Page 560
Bullet Points box

Final bullet point is incomplete. "The send() method of the AjaxRequest object"

Anonymous  Jun 23, 2009 
Safari Books Online 24
Code

document.getElementById("rockImg").src does not work correctly. An alternative is: document.getElementById('rockImg').setAttribute("src", "rock_happy.png");

Daniel Hirschlein  May 20, 2009 
Safari Books Online 172
2nd paragraph under "Global Variable"

"your" is mis-typed as "you're"

Harry Spriggs  May 17, 2009 
Printed Page 123
Cookie Example

Can't get any of your examples to write the cookie. Cookies are enabled.

Bill Slaughter  May 09, 2009 
PDF Page 62
The answer of 2nd question

"The good news it that it isnít terribly difficult to ..." should be "The good news is that it isnít terribly difficult to ..."

pcchee  Mar 25, 2009 
Printed Page 560
Bullet Points

The last Bullet Point appears to be truncated. All it says is "The send() method of the AjaxRequest object" ....

DJPJ  Mar 24, 2009 
Printed Page 81
13th question of the puzzle

"13. An piece of data with an on/off value would be stored as this data type" AN PIECE is not correct, as P is a consonant.

Cezar El-Nazli  Feb 04, 2009 
Printed Page 103
first 'arrow' annotation to illustration

example shows the property to get the height of the client window to be clientWindowHeight - it should be clientHeight.

Anonymous  Jan 21, 2009 
Printed Page 43
3rd Paragraph of left column (Variable's dialogue)

In third line of paragraph, the word "to" is repeated: " . . . when you've got to to store information . . . "

Anonymous   
Printed Page 59
middle of sample code

the placeOrder function should take in the form object as a parameter in order for the form.submit() to work.... same error as pages 73 and 74

Anonymous   
Printed Page 71
first paragraph

CURRENT: The key to accessing a web page element with JavaScript is the id attribute of the HTML tag. REVISED: The key to accessing a web page element with JavaScript is the id attribute of the input tag.

Anonymous   
Printed Page 73
start of sample code

The sample code on page 73 and 74 won't work because the form in "form.submit()" does not have a form object to work with. I think placeOrder should probably be getting the form object in as a parameter.

Anonymous   
Printed Page 94
1st paragraph

Code for setTimeout() points to the following URL: "http://www.headfirstlabs.com/books/hfsd/" instead of "../../hfjs/".

Anonymous   
Printed Page 96
top

In the "Sharpen your pencil Solution" at the top of page 96, the comment about the millisecond calculation says, "The five-minute delay is calculated in milliseconds by first converting to minutes

Anonymous   
Printed Page 104
Sample code

I think the code for resizing the rock should work in XHTML compliant pages or it shouldn't be in the book since people can't use it in the real world. It just doesn't make sense to have code there that won't work in a 'real' web page. Can you modify it or change the example?

Anonymous   
Printed Page 122
Code Way Up Close

In the touchRock function, the operation of getting the userName first is missing. function touchRock() { userName = readCookie("irock_username"); [ Rest of code is correct ] }

Anonymous   
Printed Page 140
last sentence

The last sentence ends with ...or sometimes even more that. should probably be ...or sometimes even more than that.

Anonymous   
Printed Page 201
top of 3rd column

I believe the word "inconventional" s/b "unconventional".

Anonymous   
Printed Page 217
2nd paragraph

The sentence ...it's worth making changes to your code so that is more "elegant" s/b ...it's worth making changes to your code so that it is more "elegant"

Anonymous   
Printed Page 226
2nd to last sentence on page

The sentence - I am aware that there are lot of different... s/b I am aware that there are a lot of different...

Anonymous   
Printed Page 234
sharpen your pencil solution

In the fourth line of the solution the variables i and j need to be switched, right now it says: alert ("seat " + i + "in row " + j + "is available."); it should say alert ("seat " + j + "in row " + i + "is available.");

Anonymous   
Printed Page 237
2nd paragraph

Under the second large paragraph with the seat# functions, <img id="seat14" src=" alt="" /> is missing a quotation mark under src=. It should be <img id="seat14" src="" alt="" /> instead.

Anonymous   
Printed Page 261
Sidenote pointing to thermostat picture

The sentence The "current temperature" display lets users know the current temperature so that they can make adjust the heat with more accuracy. s/b The "current temperature" display lets users know the current temperature so that they can adjust the heat with more accuracy.

Anonymous   
Printed Page 274
There are no Dumb Question. Answer #3 in the 2nd paragraph

Original text "So when you assign a function to an event handler, as you do in a moment..." Correction "So when you assign a function to an event handler, as you will do in a moment..."

Anonymous   
Printed Page 295
Title at the top of the page

the title Form field follow a chain of events s/b Form fields follow a chain of events

Anonymous   
Printed Page 300
highlighted code

I'm not sure if you would consider this a mistake. I think that I read in the XHTML Head First that there should probably be a space between the /> and everything preceding it in an empty tag. Like this: <br/> to <br /> just to accommodate older browsers. On page 300-302, the code <input id="phone" name="phone" type="text" size="12" onblur="validateNonEmpty(this);"/> there is no such space.

Anonymous   
Printed Page 309
Second question on left

Perhaps I am misunderstanding this, but on page 309 it says "The purpose of this.form in the Bannerocity code is to gain access to the help text element that is associated with a particular input field. Remember that this.form is a reference...." I understand the concept presented here but I don't see it being used, which confuses me as to why the text above implies that it is being used. If this method comes up in later pages, why not put this question after it comes up in the book? To me, it seems like it might confuse a reader who has never seen this before since it hasn't even been used in the book yet. What is being used is a document.getElementById('help_text_name') instead of a this.form["help_text"].... especially since the book mentions that the form approach is more concise but it doesn't seem to be using it?

Anonymous   
Printed Page 321
to the right of the only paragraph on the page

there is a "/d/" which is right of the paragraph. It points towards "catch22", but if it's pointing to that string..shouldn't the regular expression look like "/dd/"?

Anonymous   
Printed Page 336
the examples below the 2nd paragraph

You give 2 examples of character classes, one is /d[iu]g/ and the other is /$d[d.]/ . Shouldn't that second example be /$d[.d]/? The difference is between the brackets.

Anonymous   
Printed Page 338
"Sharpen your pencil Solution", second answer

On page 338, the answer key shows the answer is return validateRegEx ( /^[w.-_/+]+@[w_]+(.w{2,4})+$/..... but shouldn't it be validateRegEx (/^[w.-_/+]+@[w_]+[.w{2,4}]+$/..... (using brackets instead of parentheses for testing the domain suffix) ?

Anonymous   
Printed Page 339
1 across

The crossword clue asks for the JavaScript object that supports regular expressions and the answer is given as regexp but surely it should be regex?

Anonymous   
Printed Page 373
style tag found on the right side of the page

font-color should just be color. font-color is not a valid css property.

Anonymous   
Printed Page 384
Second code sample

I think the second code sample should actually be this: decisionElem.appendChild(document.createTextNode("Decision 1 -> Scene 1: Fork in the road.")); it is currently missing the createTextNode portion.

Anonymous   
Printed Page 434
in picture as well as code on bottom exercise

The ceiling function doesn't work in either Firefox or IE. Is it in this version of the standard?

Anonymous   
Printed Page 488
First sentence of last paragraph

The sentence Safari points out that the error is on entirely different line of code, s/b Safari points out that the error is on an entirely different line of code,

Anonymous   
Printed Page 497
1st paragraph

I think that's not correct that 'undefined' and 'not defined' mean exactly the same thing. 'not defined' means, that the variable does not exists/has not been created. 'undefined' means an undefined state, the variable exists/has been created but it's not initialized (no value has been assigned to the variable) example for undefined: <code> var testVariable; alert(testVariable); </code> the result is an alert-box with message-text 'undefined' example for not defined: <code> alert(testVariable); </code> the result is a message in the error console:'testVariable is not defined'

Anonymous