
previous

page 14
next
The New Bits
var card1='';
This is where we store the first card clicked.
Notice that it's outside the functions and so is not lost when the function finishes whereas variables inside a function are erased when the function finishes.
if (card1=='') {
card1=image;
card1=image;
In English: if this is the first click, remember the card.
Note the double equals ( == ).
The overall pattern is always:
if (condition) {do something} else {do something else}
n1=n1%13;
% 13 means divide by 13 and deliver the remainder eg 28%13=2
card1='';
Making sure the next click is seen as a first click.
previous
next