My code

I suggest that you use copy & paste to replace the script section of your file and then convince yourself that it works.
On the next page, I'll go over it piece by piece.

<script>
  var card1='';
  function card_clicked(image) {
    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;
      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';
  }
  function turn(image) {
    image.src='cards/back.png';
  }
</script>