Random Quote Generator - getting quote to appear when page loads

I am working on a random quote generator. This is not necessarily for the actual Free Code Camp project, because I am not that far in the curriculum yet, and I am just building it with vanilla js and html to get some practice.

Anyway, It is working so far, but I am trying to figure out how to get a quote to appear when a user first visits the site, and not just when they first click the button. Any suggestions?

The quickest fix would be to click button the first time for user with yourBtn.click() right after html is loaded (by putting script tag before </body>).

Did you get it working… ? and if so is your code pen working/up to date ? and if not can you explain more about what you are trying to do ? because it surely works now, for what you are trying to figured out.

set window.onload to run the same function as your button that fetches quotes: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onload

1 Like