I am currently working on creating a random quote machine.
Im having trouble understanding why my second button isnt working when trying to generate the author of the quote generated.
Im very new to coding so all the help would be greatly appreciated.
within my empty p element.
and it is generating the author, but i want it to generate only when i click the sencond button and currently it generates when the quote button is clicked.
How do i make it so the author button only generates the author when i click it
Is this supposed to be like this? You are concatenating this.state.currentQuote and 1 and using the result as an array index and quotes seems undefined going by the code you have provided.
Why would you want to retrieve the quote and author separately? It looks a lot more sensible to display the quote and its author with a single button click.
In that case, do not update currentAuthor in generateQuote event handler.
In the generateQuote handler, you can update currentQuote only. And in the generateAuthor handler, look for the quotes object in this.state.quotes and update author accordingly. Something like below. Be sure to handle the case where currentQuote is an empty string appropriately.
EDIT
Alternatively, you can also store the index of the currently visible quote in state as well. In the generateQuote event handler, you can generate the random integer and update index of currently visible quote and current quote in state.
Then in the generateAuthor event handler, you can update current author only.