roop0 Posted May 2, 2006 Share Posted May 2, 2006 i've fallen in on the deep end of javascript on my first day of ever looking at the code.. which could be a good thing.. forced to either sink or swim!I need to get a random image up.. which has been easy (lots of examples) but i have two images on the page which need to correspond with each other. Come up together but randomly..Would i..use the If statement? I've been trying this but must not be getting the wording right.or.. what?thanks Link to comment Share on other sites More sharing options...
Little Goat Posted May 2, 2006 Share Posted May 2, 2006 so what do you do now?LG Link to comment Share on other sites More sharing options...
roop0 Posted May 2, 2006 Author Share Posted May 2, 2006 so what do you do now?LG<{POST_SNAPBACK}> well that was what i was hoping to get some help with Link to comment Share on other sites More sharing options...
Nakor Posted May 2, 2006 Share Posted May 2, 2006 Could you further elaborate on what you want to happen? You want to random images to come up at once? Link to comment Share on other sites More sharing options...
Webworldx Posted May 2, 2006 Share Posted May 2, 2006 I'm guessing the tutorials you've looked at have done something like: var myImages = new Array();myImages[0] = "http://....image.gif";myImages[1] = "http://....image2.gif";var randImage = Math.floor( Math.random() * myImages.length);document.write('<img src="' + myImages[randImage] + '" />'); Yes?Well all you need to do is alter the array slightly, and the final output var myImages = new Array();myImages[0] = new Array( "http://....image.gif" , "http://....image2.gif" );myImages[1] = new Array( "http://....image3.gif" , "http://....image4.gif" );var randImage = Math.floor( Math.random() * myImages.length);document.write('Image 1: <img src="' + myImages[randImage][0] + '" /> Image 2: <img src="' + myImages[randImage][1] + '" />'); Image.gif and Image2.gif always get shown together, and Image3.gif and Image4.gif always get shown together too.Hope that helps! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now