Friday, January 2, 2009

Meet the iRock, Virtual Pet Superstar

Isn't he cute?
Head First JavaScript uses this, uh, "rock" to lead us through a series of exercises. This is the "iRock." He doesn't look happy, and it's not because he's a poorly-drawn version of a rock. It's because he's not able to interact with anyone. Aw, poor rock.

In this exercise of pages 18 - 20 in the book, I will learn a little bit about events, functions and greetings.

Here are some starter learnings that seem important...

"Events are notifications that you can respond to with JavaScript code." You can respond to an event like a click, or a page finishing loading. I bet you can even respond to when a user clicks on more than one object in a row, but they're not going to teach me that stuff yet. We're starting simple.

"Functions are reusable pieces of code that perform common tasks." In other words, I wish that I could write a function to do my laundry and make my bed. Unfortunately, I don't think that's going to be taught in this book.

(onload) = when a page loads
< onload="alert('I Am the Best Pet Rock You'll Ever Have!');">
(This is an evil event/alert that I will never use again, unless a tutorial makes me.)

(onclick) = when a user clicks

See how this exercise pans out at iRock: The Virtual Pet

No comments:

Post a Comment