Can't get this quote generator to work?

Can't get this quote generator to work?
0

#1

This is my random quote generator: https://codepen.io/joellemulzac/pen/KZMeXy

For some reason, the tweet button only works when I put the variable randomNumber outside of the function randomQuote(), and a quote doesn’t show up when the page first loads. Any ideas on what may be causing these problems? I would greatly appreciate the help.

Joelle


#2

That is because you defined randomNumber locally inside the function randomQuote. Outside that function, randomNumber is undefined.

That is because you only execute randomQuote when the button is clicked. If you want to load a quote when the page loads, try executing the function somewhere outside the event handlers.


#3

Thank you so much for your reply! I was able to fix it.