If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

As you have noticed that isn’t random in fact you will only ever get the first image, or maybe the second image due to where you increment your variable “index”

To display a random number you need to use the Math.random() object

Here is an edited version of your function if you notice I have put your “index” variable inside the function, you are not using it anywhere else so it is a good idea and good practice to keep your variables localised you could get rid of it all together but I didn’t want to butcher your code too much

As you have noticed that isn’t random in fact you will only ever get the first image, or maybe the second image due to where you increment your variable “index”

To display a random number you need to use the Math.random() object

Here is an edited version of your function if you notice I have put your “index” variable inside the function, you are not using it anywhere else so it is a good idea and good practice to keep your variables localised you could get rid of it all together but I didn’t want to butcher your code too much