Tell us what’s happening:
Hey guys I’m trying to build this project using React and am able to display the data on the web page …I now need to figure out how to load a random quote when clicked on the button …although the code looks okay to me not sure what I’m missing…can anyone help?
Click here to see the code
Your code so far
Your browser information:
User Agent is:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/184.108.40.206 Safari/537.36
Challenge: Front End Development Libraries Projects - Build a Random Quote Machine
Link to the challenge:
You are setting a single quote on mount then you try to index into the array of just that single quote.
You want to set the state array to all the quotes and then index into it to get a single quote. You can do the indexing in the render method for example.
I would also suggest you do not hardcode any values in the
randomQuotes method. Use the actual length of the array instead. If the API changes the hardcoded value can fail.
Second point: Yes I do know that and this is just for testing which I’ll change later but regarding the main problem I did not really understand what you are trying to tell me
Add all the quotes to the state array in the fetch. Then use the state array to get each individual quote by indexing into it.