The earlier suggestions for use strict; are good ones. It helps you catch typos in your code. I'm going to go out on a limb and guess that there's a typo near this line:
And that you may really have something else, like this:
If you didn't do this originally, try to cut-and-paste code directly into the web browser when you submit a code sample. That way we can see if there are any typos in the original code. Your code, as you've written it here, seems to work for me.