Home > Mobile >  Random Image Error Icon in HTML, javaScript
Random Image Error Icon in HTML, javaScript

Time:05-29

I am a beginner at HTML and Stack Overflow. I was trying to make this thing where there is an image that changes every few seconds. I was able to get this done but for some reason although all my 3 pictures show up, I have an extra image error icon that shows up once in a while and I don't know why. I only have 3 images so I am not sure why this image error icon shows up. Any help would be greatly appreciated.

This is the link to the code: http://tpcg.io/RJ6X5A

Click the Preview button on the top right corner and it should work.

CodePudding user response:

Generating the random index is not correct. Use images length (3) instead of 4

let random = Math.floor(Math.random() * images.length); 
  • Related