This is a basic javascript code for showing a random image in browser , you cand show any type of image and as many as you wish
Original source
This is a basic javascript code for showing a random image in browser , you cand show any type of image and as many as you wish
Original source
21 responses to “Javascript Random Image Tutorial”
hey papi
Can you randomize combinations of images?
im not sure if im suppose to dance or to code 😂
Como posso colocar titulo, texto, nome do autor, imagem e links em um card para aparecer diário?
can someone please tell me why on my reaction game the teal colored box and purple circle wont come back up randomly im getting my first grey hair trying to do this it cant be that far off from what i got in the link.
https://jsbin.com/dogunudile/1/edit?output
you can also just do document.write("<img src = "img/" + Math.floor( 1 + Math.random() * 9) + ".png" />"); and make sure your files are named in a sequence.
How do I do if I want to add text under the images?
Neylini – Muleina
=== > exactly the same as …
you can use php to generate the array for you
I have about 2000 images is there an easier way to do this.
Commence the mute button!!!!! D:
@HELLOclan Thanks , Romanian music rocks ! 😀
Best programming song ever
Ah… arrays are indexed from 0, not 1. That means you need to bump the indices all down one (0,1,2) and delete the "if (rnd ==0) { rnd=1; } bit, as it isn't necessary.
It won't run as you show it in your tutorial.
@rooker77
that is macromedia dreamwaver
@MrJustTryin
Well .. in this case we have a if statement witch basically says if variable rnd value equals to 0 then set variable rnd value to 1. If you say rnd = 0 in any programming language that means that variable rnd value equals to 0 (like you are setting up that value) but if you say rnd == 0 you check to see if variable rnd is equal to 0 .
Thanks for viewing my videos !
what does the == sign mean?
Thank U for the Great Vid!
@ashkonh Thanks for viewing my tutorials ! by doing so you support me and motivate me to do more work 🙂
@huasentertainment well .. javascript is a client side scripting language so it cannot read the content of a directory you will have to do that with some other language ex php witch is server side and populate the array then let javascript do its job , have fun !
Thanks! Great video. Right to the point and no ads; wonderful post.