Getting random JS array photo to load

I am working on my first project for FCC, and I have added a javascript photo array button, to where it will display a random photo when it is clicked. That works fine, but I am trying to figure out how to get the photos to load at random anytime the browser loads.

Tribute Page

any suggestions?

You can actually simulate a click on the button.

Put this at the end of your script:

randomizer.click();

I would also advise you look into the other events that are available to add to your elements via addEventListener.

is there anything else I should do? I just tried that and it didnt do anything

No, it should be enough. What browser are you using?

I mean, you can also extract the function and call it when the user clicks the button and when the page loads.

randomizer.addEventListener("click", randomPicture);

window.onload = randomPicture;

function randomPicture() {
  var randNum = Math.floor(Math.random() * movieImages.length) + 0  
    
    randImg.src = movieImages[randNum] ;
}
1 Like

That worked perfectly! Thank you! this has been taking me a long time to try and figure out.