

page 9
You're probably wondering why sometimes I specify width and at other times I specify height. Basically I always use height for images. All the browsers that I've tested on will work out the width so that the image does not distort but the reverse is not always true (Safari for example). For all elements apart from images, I use width.
Clearly we need 5 cards so I'm going to set up a global array, g_cards to hold their values and we'll need my Random function from Project 2.
But before you race off to fetch it, I've got a better idea.
So far I've provided you with three functions: Random, Sort and Shuffle. In this tute I'm going to provide two more. These two will allow you to Hide or Show an element by providing its id.
I've combined these 5 functions into a single file, library.js. Here is the file. Now all you will need in your head section is:
If we choose the 5 cards randomly they will hardly ever be the same so the game won't work very well. Check out my pick0 function which cleverly picks an appropriate new first card:
var r=Random(5);
if (r==1) g_cards[0]=g_cards[1];
if (r==2) g_cards[0]=g_cards[2];
if (r==3) g_cards[0]=g_cards[3];
if (r==4) g_cards[0]=g_cards[4];
if (r==5) g_cards[0]=Random(52);
}