@mabismad, you have to understand, the book he is following purposely leads to less than optimum code to then show you how to improve it. You cant just pull a section of code from the book. You really have to follow it through from the beginning. It is not really written in such a way you can just jump into the middle of it. I would recommend to anyone to get a copy. It is a good read for any skill level.
Also, go into it understanding that approach. If you pull a code block, paste it into your editor, and hit ‘go’, and it doesn’t work… make sure that the next paragraph in the book doesnt begin with “Well that didn’t work, did it. Let’s see why.”
Hahaha, I learnt that very early on in the book so I actually read to the end of the chapter before concluding that something is off!