previous

page 31

next
My Final File
<style>
body {
background-color:green;
}
div {
text-align:center;
}
img {
height:23vmin;
}
</style>
<body>
<script>
var click_ok=true;
var arr=[6,7,8,9,10,11,12,1,32,33,34,35,36,37,38,27];
Shuffle(arr);
var s1="<img src='cards/back.png' n='";
var s2="' onClick='card_clicked(this);'>";
var n=0;
for (var r=0; r<4; r++) {
document.write('<div>');
for (var c=0; c<4; c++) {
document.write(s1 + arr[n] + s2);
n++;
}
document.write('</div>');
}
function Shuffle(array) {
var i,j,temp;
for (i=array.length-1; i>0; i-=1) {
j=Math.floor(Math.random()*(i+1));
temp=array[i]; array[i]=array[j]; array[j]=temp;
}
}
var card1='';
var back_src='';
function card_clicked(image) {
if (back_src=='') {
back_src=image.src;
}
if (image.src==back_src && click_ok) {
var n=image.getAttribute('n');
image.src='cards/'+n+'.png';
if (card1=='') {
card1=image;
} else {
var n1=card1.getAttribute('n');
var n2=image.getAttribute('n');
n1=n1%13;
n2=n2%13;
click_ok=false;
if (n1==n2) {
setTimeout(clear,1000,card1);
setTimeout(clear,1000,image);
} else {
setTimeout(turn,2000,card1);
setTimeout(turn,2000,image);
}
card1='';
}
}
}
function clear(image) {
image.src='cards/0.png';
click_ok=true;
}
function turn(image) {
image.src='cards/back.png';
click_ok=true;
}
</script>
</body>
previous
next