Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Beginning JavaScript 5th Edition
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning JavaScript 5th Edition
This is the forum to discuss the Wrox book Beginning JavaScript, 5th Edition by Jeremy McPeak; 978-1-118-90333-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript 5th Edition 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 Display Modes
  #1 (permalink)  
Old December 28th, 2015, 01:08 AM
Registered User
Points: 45, Level: 1
Points: 45, Level: 1 Points: 45, Level: 1 Points: 45, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2015
Posts: 5
Thanks: 5
Thanked 2 Times in 2 Posts
Question Chapter 9 - Examples 4 and 5

First, there seems to be a typo or two for the Chapter 9 Example 4 at the very top of the HTML code, at least using the epub version for the 5th edition I purchased a few days ago:
-transitional.dtd”>

In example 5, it also goes from using "new-style" to using "newStyle", I don't think it's intentional.

Second, I am having trouble understanding why Example 5 does not result in italicized text. When I inspected the source code using Firefox's developer tools, it seems there's some conflict with Arial and Italics when done in the way of Example 5, but not when you do it in the way of Example 4. My question is why this should be.

For reference, here is example 5 (and a link to the book's example):
http://beginningjs.com/examples/ch9_example5.html

HTML Code:
<html lang="en">
<head>
    <title>Chapter 9, Example 5</title>
    <style>
        #divAdvert {
            font: 12pt arial;
        }

        .new-style {
            font-style: italic;
            text-decoration: underline;
        }
    </style>

</head>
<body>
    <div id="divAdvert">
        Here is an advertisement.
    </div>

    <script>
        var divAdvert = document.getElementById("divAdvert");
        divAdvert.className = "new-style";
    </script>

</body>
</html>
If I add
Code:
divAdvert.style.fontStyle = "italic";
, it does italicize.
Reply With Quote
The Following User Says Thank You to snowcrasher555 For This Useful Post:
Moby (January 3rd, 2016)
  #2 (permalink)  
Old January 3rd, 2016, 09:35 PM
Authorized User
Points: 134, Level: 2
Points: 134, Level: 2 Points: 134, Level: 2 Points: 134, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2015
Location: the sea
Posts: 10
Thanks: 4
Thanked 5 Times in 4 Posts
Default

I am experiencing the same thing. I have tried changing fonts and can find none that will apply italic when the element is assigned to the class using the className property.

divAdvert.style.fontStyle = "italic"; displays the arial text in italic just fine. The text-decoration portion of the new-style class works, and if I add things like color: green, etc., it applies them as well. I also tried changing fontStyle to oblique instead of italic. There was no difference.

I created a heading and directly assigned it to the new-style class -- it displayed in underlined arial italic as expected.

Have you found an answer yet, snowcrasher555? I suspect we will not get one here, this board seems pretty deserted. Perhaps this should be asked elsewhere.
Reply With Quote
The Following User Says Thank You to Moby For This Useful Post:
snowcrasher555 (January 3rd, 2016)
  #3 (permalink)  
Old January 3rd, 2016, 09:58 PM
Authorized User
Points: 134, Level: 2
Points: 134, Level: 2 Points: 134, Level: 2 Points: 134, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2015
Location: the sea
Posts: 10
Thanks: 4
Thanked 5 Times in 4 Posts
Default

Okay, I have figured it out!
When I move font: 12pt arial into the .newstyle section of the CSS, it works fine. font is a shorthand CSS property, and any unspecified properties are the default, so font-style is being set to normal and the id (divAdvert) style is being given precedence over the class (new-style), as should be expected.

Changing the specifications of #divAdvert from font: 12pt arial; to font-family: arial; and font-size: 12pt; does not set a font-style, so the text displays in italic as intended.
Reply With Quote
The Following User Says Thank You to Moby For This Useful Post:
snowcrasher555 (January 3rd, 2016)
  #4 (permalink)  
Old January 3rd, 2016, 11:31 PM
Registered User
Points: 45, Level: 1
Points: 45, Level: 1 Points: 45, Level: 1 Points: 45, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2015
Posts: 5
Thanks: 5
Thanked 2 Times in 2 Posts
Default

I was on the verge of posting this on Stack Exchange or some other website; thanks so much for figuring it out and explaining it so well! That makes sense now. It seemed like not a big deal but it was bugging me for a while. Cheers.
Reply With Quote
The Following User Says Thank You to snowcrasher555 For This Useful Post:
Moby (January 4th, 2016)
  #5 (permalink)  
Old January 4th, 2016, 09:46 AM
Authorized User
Points: 134, Level: 2
Points: 134, Level: 2 Points: 134, Level: 2 Points: 134, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2015
Location: the sea
Posts: 10
Thanks: 4
Thanked 5 Times in 4 Posts
Default

Thanks for pointing out the issue in the first place. I wish the errata section was being kept up, but it doesn't seem to be. Please do post any other errors you find and I will try to do the same.
Reply With Quote
  #6 (permalink)  
Old January 8th, 2016, 03:36 AM
Registered User
Points: 26, Level: 1
Points: 26, Level: 1 Points: 26, Level: 1 Points: 26, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2016
Posts: 8
Thanks: 2
Thanked 1 Time in 1 Post
Default

Yes, it's really a pity that the errata page has been abandoned.
snowcrasher555,Moby, it seems that you have covered a solid part of this book so far. Does it contain a lot of typos, inaccuracies and so on?
I had seriously hoped that "Beginning Javascript" is the best book on the market for a JS-beginner but now that I see that there are a few typos and the errata page is not being maintained..that's sort of discouraging.
Cheers!
Reply With Quote
  #7 (permalink)  
Old January 8th, 2016, 02:20 PM
Registered User
Points: 45, Level: 1
Points: 45, Level: 1 Points: 45, Level: 1 Points: 45, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2015
Posts: 5
Thanks: 5
Thanked 2 Times in 2 Posts
Default

Well, I have to say that I would still recommend the book. There are no shortage of books out there, but I felt like I kind of understand how and why Javascript works by reading and working through chapters in this book. Many books start teaching programming concepts and syntax without even mentioning the web until much later, but I felt like this book did a good job of keeping me motivated. I worked through all the examples of the chapters I have read (that's why I found the error mentioned in this particular thread). With that said, I have some programming experience (in other languages), though I am not a professional by any stretch. Perhaps Moby can also give his thoughts about this book.

I have sort of jumped around in the chapters. There are typos, but this is the biggest one I found, and more often than not, it's not as big a deal. That's not to excuse the errors (although every book will have its share of errata), but I actually think it's a pretty good book in general, and the reason I started with it is that it is recommended as part of a self-learning track on the website Javascript is Se Xy although it refers to the older edition, and some chapters have been combined and/or separated.

I think possibly the errata page has not been abandoned, but they just don't have a central place to receive reports of them, or they have forgotten to check this forum regularly. Actually, as I check the website for the book, they ask that users submit an Errata form: http://www.wrox.com/WileyCDA/WroxTit...Cd-ERRATA.html

I admittedly have not submitted with that form, so maybe that's the issue. UPDATE: I have tried to submit and detail the issues regarding errata and the forum using the Errata Form. We will see if it does anything.

Last edited by snowcrasher555; January 8th, 2016 at 02:39 PM.
Reply With Quote
  #8 (permalink)  
Old January 8th, 2016, 02:37 PM
Registered User
Points: 26, Level: 1
Points: 26, Level: 1 Points: 26, Level: 1 Points: 26, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2016
Posts: 8
Thanks: 2
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by snowcrasher555 View Post
Well, I have to say that I would still recommend the book. There are no shortage of books out there, but I felt like I kind of understand how and why Javascript works by reading and working through chapters in this book. Many books start teaching programming concepts and syntax without even mentioning the web until much later, but I felt like this book did a good job of keeping me motivated. I worked through all the examples of the chapters I have read (that's why I found the error mentioned in this particular thread). With that said, I have some programming experience (in other languages), though I am not a professional by any stretch.

I have sort of jumped around in the chapters. There are typos, but this is the biggest one I found, and more often than not, it's not as big a deal. That's not to excuse the errors, but I actually think it's a pretty good book in general, and the reason I started with it is that it is recommended as part of a self-learning track on the website Javascript is Se Xy although it refers to the older edition, and some chapters have been combined and/or separated.

I think possibly the errata page has not been abandoned, but they just don't have a central place to receive reports of them, or they have forgotten to check this forum regularly. Actually, as I check the website for the book, they ask that users submit an Errata form: http://www.wrox.com/WileyCDA/WroxTit...Cd-ERRATA.html

I admittedly have no submitted with that form, so maybe that's the issue.
Thank you for a detailed answer. I also started with this book after reading "How to Learn JavaScript Properly | JavaScript is ****************".
There are really plenty of books on Javascript for beginners. Trouble is that most of them either don't teach Javascript and just offer some ready code snippets without detailed explanations of how it works.. or they try to teach Javascript but in a form that I don't like.
I really like the way "Beginning JS" is written. There's "Javascript and jQuery book" by Jon Duckett and Headfirst Javascript Programming but they are TOO visual for me.
I could also recommend (I'm really sorry, Wrox) "Modern Javascript. Develop and Design" by Larry Ullman. It's not often referred to but the book is really great. Covers all the necessary information in a lively and easy-to-follow manner.
P.S. Unfortunately, it seems that private messages are disabled on this forum. How do you practice JS apart from doing exercises from the book? What are your future plans in mastering web development?
I just started playing around with jQuery. Spend the whole day and passed the jQuery track on codecademy.com and skimmed through several jQuery books that are usually recommended. That's fairly entertaining,I must admit.
Of course, I wish I could do all these things using vanilla Javascript. But why invent the wheel, considering that even huge web projects actively use jQuery?
Reply With Quote
  #9 (permalink)  
Old January 8th, 2016, 03:39 PM
jmcpeak's Avatar
Wrox Author
Points: 467, Level: 7
Points: 467, Level: 7 Points: 467, Level: 7 Points: 467, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2005
Location: , Texas, USA.
Posts: 87
Thanks: 0
Thanked 17 Times in 16 Posts
Default

Well I'm late to the party, but I'll add my $0.02.

Quote:
First, there seems to be a typo or two for the Chapter 9 Example 4 at the very top of the HTML code, at least using the epub version for the 5th edition I purchased a few days ago:
-transitional.dtd”>
It must be a problem with the epub version. All of the examples have HTML5 doctypes, and there are no remnants of XHTML DTDs in the physical book.

As to the actual issue in Ch9 Ex5, it (and me, apparently) falls prey to CSS specificity. IDs have a higher specificity than classes. So because I used the font property in the ID selector, it overrides font-style in the .new-style selector. As Moby found, the solution is to change the #divAdvert rule to:

Code:
#divAdvert {
    font-family: arial;
    font-size: 12pt;
}
Errata isn't abandoned; there's just only been one report for this edition. As mentioned, errata is reported using a separate from (https://hub.wiley.com/community/support/wrox). The submissions are processed and sent to the authors for verification. I don't know how long it takes for an errata submission to reach me, but it will.

Unfortunately, every book has errors. With the size and scope of such a large project, bugs are inevitable... even with the author and several editors. This edition was a huge reorganization from prior editions, and remarkably very little has been reported.

Quote:
How do you practice JS apart from doing exercises from the book?
Projects. Think of something you want to build and build it, but it's important to pick realistic projects. Start with something manageable, and as you gain confidence, build more complex projects.

Quote:
Of course, I wish I could do all these things using vanilla Javascript. But why invent the wheel, considering that even huge web projects actively use jQuery?
Using jQuery is fine. It's a tool that, when used correctly, can make you more productive. But it is also JavaScript, so be sure and have a solid understanding of the language and its behavior.

Last edited by jminatel; May 18th, 2016 at 04:31 PM. Reason: new Wrox customer help site https://hub.wiley.com/community/support/wrox
Reply With Quote
The Following 2 Users Say Thank You to jmcpeak For This Useful Post:
snowcrasher555 (January 9th, 2016), Wilfred Desert (January 8th, 2016)
  #10 (permalink)  
Old January 8th, 2016, 03:49 PM
Registered User
Points: 26, Level: 1
Points: 26, Level: 1 Points: 26, Level: 1 Points: 26, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2016
Posts: 8
Thanks: 2
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by jmcpeak View Post
Well I'm late to the party, but I'll add my $0.02.



It must be a problem with the epub version. All of the examples have HTML5 doctypes, and there are no remnants of XHTML DTDs in the physical book.

As to the actual issue in Ch9 Ex5, it (and me, apparently) falls prey to CSS specificity. IDs have a higher specificity than classes. So because I used the font property in the ID selector, it overrides font-style in the .new-style selector. As Moby found, the solution is to change the #divAdvert rule to:

Code:
#divAdvert {
    font-family: arial;
    font-size: 12pt;
}
Errata isn't abandoned; there's just only been one report for this edition. As mentioned, errata is reported using a separate from (http://wrox.custhelp.com/app/ask). The submissions are processed and sent to the authors for verification. I don't know how long it takes for an errata submission to reach me, but it will.

Unfortunately, every book has errors. With the size and scope of such a large project, bugs are inevitable... even with the author and several editors. This edition was a huge reorganization from prior editions, and remarkably very little has been reported.



Projects. Think of something you want to build and build it, but it's important to pick realistic projects. Start with something manageable, and as you gain confidence, build more complex projects.



Using jQuery is fine. It's a tool that, when used correctly, can make you more productive. But it is also JavaScript, so be sure and have a solid understanding of the language and its behavior.
Thank you very much for answering. I shouldn't have used the word "abandoned". That was too emotional. But it was mostly due to the fact that your book is my personal favourite. Many people recommend "Eloquent Javascript" to be the best fit for beginners whereas I disagree on that. "Beginning Javascript" is much more structured and reader-friendly.

As for jQuery, do you think that it's necessary to understand how what you do using jQuery can be done using vanilla Javascript?
Reply With Quote
Reply


Thread Tools
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
Chapter 9 examples richoaus Book: Professional Microsoft SQL Server Analysis Services 2012 with MDX and DAX 2 November 15th, 2015 03:45 AM
examples in Chapter 3 rna5132 JSP Basics 8 October 7th, 2003 12:59 PM



All times are GMT -4. The time now is 10:34 AM.


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