Making an image flip on "click"

I put together a short bit of html coding to make an image flip on click. I copied sample coding from a website exactly as supplied, but although it works on the sample site, it refuses to work for me. What could possibly be the problem? Here is the coding:

Hey, your problem here is that your JavaScript is running before your HTML is initialized, so essentially it’s trying to get an element that doesn’t exist yet. You can solve this by just putting your <script> tag all the way to the bottom of the body.

Wow, That was embarrassingly simple. Thanks.