When the page is loading scripts, whatever is below them does not exist.
There are a couple of ways to deal with this.
All information is in the book about how it uses the Core library to init your code.
Another way is becoming more and more popular now that removes the need for such init loaders, and that is to put your script at the end of the body, just before the </body> tag.
By placing your script however at the end of the body, the rest of the page above it has already loaded and is available for your script to work with.