HeadFirst HTML5 Programming - Ch4 example code changes not explained

Hi

I have a copy of HeadFirst HTML5 Programming that I purchased from you (PDF version) - I have a few HF titles and I think they are generally fantastic. My query is about the code example in Chapter 4 (Cinema example) in the book does not appear to work. I checked the link to the discussion forum for the book and several other people have had problems but I can see no explanation. I have also downloaded the sample code and it is significantly different from what is explained in the book. This is very confusing and I would really appreciate an explanation of this code and why the variation was necessary? It does seem very convoluted and repetitious - something I thought we should try to avoid and minimise through reusable functions?

Thanks
Troy
1 person has
this problem
+1
Reply
  • Hello Troy,

    I have forwarded your question on to our Book Tech staff, so they can help you find a solution. If you ever have any questions or issues with the content of a title, you can also contact them directly at booktech@oreilly.com or call them at:

    1-800-889-8969
    or
    1-707-827-7019 (outside the USA)
    7:30 am to 5:00 PST

    Best regards,
    Paul Fichera
    Customer Service Representative
    O'Reilly Media
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited kidding, amused, unsure, silly

  • Hi Troy, Can you elaborate on the issue you're having with the code?

    Thanks!

    Elisabeth
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited kidding, amused, unsure, silly

  • Hi Elizabeth

    I really appreciate you getting back to me - I'm new to JS and programming so I hope this explanation of my issue is reasonably cogent.

    My issue is that the code example for cinema in the HF5-programming PDF (pages 139 to 141) has a single use of the getNextShowing(movie) function. My understanding is that the function will use the movie argument passed to it to access an array list of movie/time values to generate the output. However, when I run this code as set out in the book it does nothing. Looking at the discussion board for this book, others seem to have had this issue.

    In contrast, the Chapter 4 example (cinema) from the download code - downloaded from my purchases at O'Reilly - works in various browsers (i.e. safari, opera) but is quite different in terms of its structure, it now includes:

    - a getMovie function with ( with a series of 'this' declarations).
    - a getNextShowing function within each of the declared movie variables.
    - also has variables with the movie names that use the 'new' keyword and no longer uses curly braces to hold the object's content. This last part is particularly confusing because we now seem to have two different var for each movie (i.e. var movie1 and var plan9Movie which is declared within the window.onload = function at the beginning of the example) ?

    So my issue in a nutshell is that I don't understand why the book example and the download code example are so vastly different from each other? Why was the deviation necessary and can it please be explained? For a first object example it no longer looks simple or straight forward given I only have the explanation in the book as a guide.

    As an aside I use a program called Espresso to write code which provides error checking and highlights mistyped code etc. So after re-checking a few times I am reasonably certain I have typed in the code from the book faithfully and accurately.

    Thanks
    Troy
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • Hi Troy,
    I think I see the problem: the version of the code online is the version once you complete the next two steps (in the remainder of the chapter).

    I've added a version named "cinema-start.html" which should match the version on pages 139-141.

    https://github.com/bethrobson/Head-Fi...

    This code works for me, hopefully it will for you too!

    Let me know if this solves the problem. Also, if you could point me to the forum where people are having issues (I was unable to find it yesterday when I looked for it), I can hopefully help them out too.

    Thanks

    Elisabeth
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited kidding, amused, unsure, silly