Sams Teach Yourself JavaScript in 24 Hours

Sams Teach Yourself JavaScript in 24 Hours

By Michael Moncur

Q&A

Q1:

Is this about as complex as a JavaScript program can get?

A1:

Not by any means. You can write much more complicated scripts that can encompass several different HTML files.

Q2:

I thought the images in the images array were indexed starting with 0, but the game uses the indexes 1–5 to display the cards. How does this work?

A2:

The game includes a title graphic at the top, which uses the images[0] space. If you add or remove graphics from the top of the page, be sure to change the indexes accordingly.

Q3:

Why use an object to store cards when the filename (such as 10h.gif ) already stores a card's information?

A3:

Just for convenience. By using an object, you can individually access the card's value and its suit, which are heavily used by the scoring routine.

Share ThisShare This

Informit Network