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.
Version |
Location |
Description |
Submitted by |
Date Submitted |
PDF |
Page 267-268
all page |
The code is not behaving as expected.
The line `goLightning();` causes the lightning effect to start immediately upon page load. However, when clicking on the page, the statement `window.onfocus = goLightning;` is triggered, resulting in the animation from two running functions.
Removing the line `goLightning();` doesn't help because we want the lightning effect to appear immediately after the page loads. Additionally, removing the line doesn't solve the problem in Safari. If we open a new tab and switch back to the window with our program, the `goLightning()` function is called twice in a row, causing the inability to cancel the lightning effect with the `stopLightning()` function.
My solution to this problem is to create a flag variable that tracks whether the `goLightning()` function is currently running. Here's the implementation:
/* Start of the code */
var isLightningRunning = false; // Create a flag variable and initialize it to false
function goLightning() {
if (!isLightningRunning) { // Check the flag value before executing the function body
int1 = setInterval(lightning_one, 4000);
int2 = setInterval(lightning_two, 5000);
int3 = setInterval(lightning_three, 7000);
isLightningRunning = true; // Update the flag value at the end
}
}
function stopLightning() {
clearInterval(int1);
clearInterval(int2);
clearInterval(int3);
isLightningRunning = false; // Update the flag value
}
/* End of the code */
By introducing the `isLightningRunning` flag, we can control the execution of the `goLightning()` function and prevent it from being called multiple times or conflicting with the `stopLightning()` function.
|
Natka |
Jun 27, 2023 |
Printed |
Page 236
highlighted code block for hit and stand buttons |
The image source for the image within #btnHit is "images/deck_small.jpg", but should be "images/hit_small.jpg".
|
Brian Futrell |
Jul 15, 2022 |
Printed |
Page 362
In the if else if else |
Shouldn't the code in the if else if else be:
$('#finishers_all'). append(info);
instead of
$('finishers_all').append(info);
|
Anonymous |
Mar 04, 2017 |
PDF |
Page 277
Last line of the randomize() function |
The last line of the randomize function reads :
"$(this).animate({left:"-="+move_to+"px"},500);"
It should read as:
"$(this).animate({left:"-"+move_to+"px"},500);"
Note the removal of '=' before the variable move_to.
We're setting the location of the individual strips as a factor of the target position. If the target position is, say, 7, then the animation should reposition the image strip such that it's left value is equal to 7*w (== 7*-367), and NOT increment the present value by 7*w. If this error persists then after a few clicks, the image strips leave the frame empty(as the image strip is exhausted) and the brown background shows through.
|
Somenath Sinha |
Aug 09, 2016 |
Printed |
Page 28
United States |
page 28, as the person reported with fadeIn not working this seems to be a change in the base jquery language version(1.6.2 works fine, 1.11.1 shows different behavior)
|
James Barnes |
Oct 14, 2014 |
PDF |
Page 262
within the solution box of the jQuery Magnets |
both functions stopLightning and goLightning closing braces are followed up by semicolons. a function closing braces should not be followed by a semicolon.
|
Sherif Mahmoud |
Nov 22, 2013 |
PDF |
Page 238
Solution |
Before:
On the June 28, 2013 update, you removed the line below from pages 233 & 234. But you forgot to add it on the correct page. Without it, the cards array will always be empty so the SumCardTotal function on p238 will never run.
hand.cards[hand.cards.length] = c;
After:
Once you get to page 238, add the above line (2nd line below) in the hit function so it looks like this:
...
used_cards[used_cards.length] = index;
hand.cards[hand.cards.length] = c;
var $d = $("<div>");
...
|
Anonymous |
Sep 03, 2013 |
PDF |
Page 248
Solution |
1) index.html
Before: src is blank
<div id="result"><img src="" id="imgResult"></div>
After: add path to image
<div id="result"><img src="images/check.png" id="imgResult"></div>
2) my_scripts.js
Before: # is missing
$("result").toggle();
After: add # in front of 'result'
$("#result").toggle();
|
Anonymous |
Sep 03, 2013 |
|
28
bold code sample |
fadeIn(1000) has no visible effect and is not consistent with the exercise goal. fadeToggle(1000) gets the job done.
|
Anonymous |
Aug 01, 2013 |
PDF |
Page 230
infobubble poinitng to part of loop syntax |
In the "look up close"
for the
"for( var i=0 ; i < my_arr2.length ; i++ ){" example,
there is infobubble
".length is a common
method for all arrays.
It tells you how many
items the array has."
length is property, not method.
|
nenad |
Jul 31, 2013 |
PDF |
Page 260
Test Drive output windows |
When opening the page in Chrome, each line reporting a blur or focus is printed twice. This error also causes problems with the Monster Mash lightning solution in Chapter 7.
The error occurs due to the way in which Chrome processes onblur and onfocus events. When a window loses focus, it fires two onblur events; similarly, onfocus is triggered twice each time a page gains focus.
To correct this for onblur, a flag variable can be declared and initialized to false. When the event handler for onblur is triggered, if the flag is set to false, the function is executed and the flag is set to true. Otherwise, it does nothing. Then, the event handler for onfocus can set the flag to false again.
The solution is similar for onfocus.
|
Benjamin Wyatt |
Apr 21, 2013 |
Printed |
Page 236
highlighted new code |
When you add the new controls, you have a btnDeal and you add a btnHit and btnStick. But then in the corresponding new CSS, you show btnHit, btnStick, and btnRestart.
I think you add btnRestart later in the chapter, and I think btnDeal doesn't need this CSS, but it's still very confusing that these "corresponding" code parts don't match.
|
Anonymous |
Jan 22, 2013 |
Printed |
Page 420
service.zip download code |
Line 58 of service.php: array key weight is unquoted.
weight => $row['creature_weight'],
should be
'weight' => $row['creature_weight'],
|
lemuel |
Aug 03, 2012 |
Printed |
Page 400
Ready Bake Code |
In the sightings_end.html code, the name of the first input field should be "creature_color_rgb".
|
lemuel |
Aug 03, 2012 |
Printed |
Page 365
Ready Bake PHP |
I could not get this code to run unless I included a check for the existence of the $_POST value in the first "if()". I changed this:
if($_POST['action'] == 'addRunner') { // doesn't exist on GETs
to this:
if(isset($_POST['action']) && ($_POST['action'] == 'addRunner')) {
|
lemuel |
Jul 22, 2012 |
|
242
example solution |
The example shows three tests of current_total in this order:
#1: if (this.current_total > 21)
#2: if (this.current_total == 21)
#3 if (this.current_total <= 21 && this.cards.length == 5)
If current_total is 21 on your fifth card, you not reach the 3rd test as intended. A better solution is to reverse the order of #2 and #3:
|
Lynne Brown |
Jul 08, 2012 |
Printed |
Page 249
Test Drive |
There is no code (at this point) to toggle on btnRestart so there is nothing to click on.
|
lemuel |
May 28, 2012 |
Printed |
Page 245
Test Drive |
It doesn't make sense to allow adding cards after the game is over. $("#btnHit").unbind() should be added to the three end-of-game conditions in sumCardTotal.
|
lemuel |
May 28, 2012 |
Printed |
Page 109,110,112
code box |
Within the function definition of the var hideCode, another function definition that is to run for each DOM member of class .guess_box is given a second parameter of "value". However, "value" is not used anywhere in that function definition, and removing that parameter appears to have no effect on the execution.
|
Jay Valatka |
Feb 12, 2012 |
Printed |
Page 234
middle |
the correct test is:
if(!($.inArray(index,used_cards) > -1)) {
instead of:
if(!$.inArray(index,used_cards) > -1) {
|
Anonymous |
Jan 16, 2012 |
PDF |
Page 234
top of magnet thing |
two identical card can be dealt and calling 'used_cards' at the console gives a reference error.
|
Kody Crouch |
Jan 13, 2012 |
PDF |
Page 250
last function - stick-button click handler |
The stick button makes absolutely no sense - whenever you click it you win the game! This is not how a BlackJack game should work.
|
Roman Bl?th |
Dec 04, 2011 |
PDF |
Page 244
beginning of code magnets solution |
After checking whether the variable "good_card" is still false, you first set it to false. This makes no sense at all and beginners will be quite confused to see this.
|
Roman Bl?th |
Dec 04, 2011 |
PDF |
Page 114
1st question of the 3rd dumb questions column |
The answer states that value is the same as $(this) (i.e. a jQuery object) in the .each loop, but it is the same as this (i.e. a DOM element object).
|
Anonymous |
Dec 03, 2011 |
PDF |
Page 267,268
first line of the code |
I found these code never stop the timer in my firefox browser,
I find out that the first line code should be removed:
goLightning();
otherwise, there 2 two places will call goLightning() method,
one is the first line, the other is when window is get focus,
since each time when you call setInterval, it will return a new interval ID, if you call it twice, it will return 2 different ID, the only the second one is saved in the code. when you leave the window, only the second interval is cleared, but the first one is still running,
that is why the timer always running even if you leave the window.
To fix that, the first line of the code should removed, so that we can guarantee that only setInterval only get called once.
|
Steve Zhang |
Oct 29, 2011 |
Printed |
Page 250
Bottom of the Page |
The $(:#btnRestrart") .click function needs this added to the example:
$("#imgResult").attr('src','images/check.png');
Otherwise, the #btnStick still shows the red X.
Thanks.
|
Charles B |
Oct 10, 2011 |
Printed |
Page 248
Middle of the page |
The btnRestart is not triggered by 249. If I was a totally new user to jQuery I might be confused as to why its not working. I know you guys know your stuff its just that I think this needs to be called earlier:
$("#btnStick").click(function(){
$("#hdrResult").html('Stick!');
$("#btnHit").toggle();
$("#btnStick").toggle();
$("#btnRestart").toggle();
});//end btnStick click function
I see that on the next page you make the same into a function called end but for me the app did not flow correctly until I did this. This might frustrate a new user. Thanks.
Also, in the solution there is not CSS file to style the new elements and it causes a problem in some browsers: Chrome and IE. The #results div displays a blank image on the page.
Thanks for all of your hard works guys. I love the Head First series and you haven't disappointed me :)
|
Charles B |
Oct 10, 2011 |