previous

page 10

next

I found getting the game to start off well quite tricky. Here's what I ended up with. The key idea is to start off with a reasonable set of 5 cards - i.e. not all different. What will be new for you is my j loop which counts backwards.

...
<script>
var g_cards=[];
for (var i=0;i<5;i++) g_cards.push(Random(52));
for (var i=0;i<5;i++) {
pick0();
for (var j=4; j>0; j--) {
g_cards[j]=g_cards[j-1];
}
}
for (var i=0;i<5;i++) {
var image=document.getElementById(i);
image.src='cards/'+g_cards[i]+'.png';
}
</script>
</body>
</html>

previous
next