Random image generation in Javascript
21:50 12 Nov 2014

I have a problem that I have been trying to figure out and I can't seem to find it online. I am new to Javascript and I really want to get the hang of it. Here is my problem.

I want to be able to have an image on the screen. And when the program starts a random image is chosen from a set of images. For example. Lets say I have a green button, a blue button, and a red button. When the browser loads I want the button to be displayed at random from that set of images. Here is what I have so far, bear with me here I am still learning. Now from what I understand I have the image already there. And I am using document.getElementById to get the element of the tag right? I also have the random method to pick a number between 1 and 3. Now I just have to figure out how to make it pick between the other 2 images (blue button, and green button)

Thanks for your time.

EDIT: I'd like to be able to do this without the use of arrays or objects.


  


javascript html