previous

page 8

next
Making the card vanish:

Have a close look at my latest code.
Notice that I've added another function of my own.
I'm sure you can work out what this new function does.

But of real interest is the new JavaScript function just above it, setTimeout.
You might like to try this code before reading on.

<img src='cards/back.png' onClick='card_clicked(this);'>
<script>
function card_clicked(image) {
image.src='cards/13.png';
setTimeout(clear,1000,image);
}
function clear(image) {
image.src='cards/0.png';
}
</script>

setTimeout is a JavaScript function which sets a timer going.
What we have to pass to that function is:

1. the function we want to call when the timer expires (clear);
2. how long to wait in milliseconds (1000);
3. what to pass to the function when it is called (image).

setTimeout doesn't work on older versions of Internet Explorer.

We're making real progress!
How about you add to your program so that instead of the card disappearing,
the card is turned back over after 2 seconds?
Call the new function turn - don't delete clear.

previous
next