I have a 3x4 table of images that when the page loads all the separate images load in order to make "one image" (the images are in pieces to create somewhat of a puzzle). I have a button called automate that when click will randomize the images. What I need is a function to "check" to see if a number is already used (hopefully the code helps to make sense of this).
JS to randomize images:
function auto(){
for (i = 0; i <= 12; i++){
r=Math.floor(Math.random()*12);
alert(r) // Just shows where I'm at for figuring it out
document.images[i].src="pic"+r+".gif"
}
My images are called "pic0 , pic1" etc. So the randomize number 0-12 will randomize the image source.
What I need now is a function that will step through the image 0-11 and check to see if a number has been used already to avoid duplicating the picture. This is what I have so far for that function but am stuck now.
JS for Check:
for (i=0; i < 12; i++){
check[i]=0;
}
if ( check[r] === 0)
{
document.images[i].src = "pic" + r + ".gif";
check[r] = 1;
}
else {
while (check[r] ===0){
r= (r+1) % 12;
document.images[i].src = "pic" + r + ".gif";
check[r] = 1;
}