As you can see, clicking the button generates a random number, but only once.
It doesn’t work the second time.
How can I fix it? where am I wrong?
I moved the line
var rand = quote[(Math.random()*quote.length|0)];
to inside $("#randomize).on(‘click’) and it worked for me.
However, although it is not explicitly stated, I think this project is meant to teach you how to use jquery’s AJAX, not make your own quotes.
If you’re unsure of how to start, there are a bunch of posts on the forums on this already. The basic idea is to find a website that will generate the quotes for you, get the quotes from them using AJAX, and display them.
your code only generate random number once, it is when rand variable was made.
try to move your Math.random() formula inside the on(“click”, function()) so that new random number appear each time you click the button
Thank you man! you are great!
now I’ll try this with ajax.
Hope will work…
Though some campers use an external API to get their quotes, there is no strict rule to use an external API to complete this project. The Twitch, Local Weather, and Wikipedia projects require the use of an external API to complete them. The Random Quote project is just meant to get you exposed to reading from/manipulating DOM elements and creating a dynamic application.