I came up with the project to swap images that are already displayed. I have 3 images on the page in a unordered list. Each has an Id of image1, image2, image3. and the images are called that same .jpg.
When you click a button I would like them to switch, the goal is at random. But for now I want to settle on simply switching order. Here is the code I have so far.
I am having trouble figuring out how to swap them. I loop through an array of strings with the image paths. I send that to a function. What should i look at in order to store the images and then swap them. Would a switch statement make sense here? Based on randomly generated numbers? Or would another for loop maybe make sense? This function seems to be confusing me the most.
I don't want the solution, that would get me no where, but could someone help me with the right direction.
Probably going to ask a lot of possibly stupid questions...but how else will I learn? am I right!
I used the Math.floor to get an intager for math.random, between 1 and 10, and still using an array to store the string sources, and it works!
But when i add more then one div containg the same content the script only effects the top panel, why would it not alter the others? Imagine a 3x3 square.
Joined: Nov 08, 2001
ids are singular, you can not have multiple elements with the same id.
Joined: May 15, 2011
That makes sense, I changed it around, created 2 new functions to handle the new image id's and it works.
Is there a better way of having the functions randomize the images, with out having to write out every possible position they could be in? Something more elegant?