basically, you want a list of image urls, and then you can use a common number to refer to each one.
it could working something like :
cardname2='<img src=' + JSON.stringify(randn2+'.jpg') + ' />';
sometext2.innerHTML = cardname2;
ps, i did the same thing once upon a time; see http://danml.com/pub/memory.htm
for a peek at how i did it a while back...