Random Quote Generator Tweet Button Help!

I am having trouble with one last element of my quote generator. I’ve had a look through all the similar questions on the forum but still can’t figure out how to solve the problem. Or indeed quite what the problem is.

The button opens a tweet in a separate window, however it reads ‘undefined’ in the box instead of the tweet.

From what i’ve read its something to do with defining randomQuote at the top but wherever i move it it seems to be the same and i can’t figure it out based on the answers in the other threads.

Hope someone can help me out!

Here is my pen: https://codepen.io/octavesapart/full/OgyorG/

Thanks in advance!


You never use your randomQuote variable. so will always be undefined.
But you can just use some jQuery and grab the text directly from the elements.
like $(".quote").text() instead of the variable.

Or you need to set the randomQuote variable when you get the data from the API.
would be inside the getJson function.

Cracked it with that $(".quote").text() suggestion! I had tried something like that earlier but must have gotten something wrong and moved on too quickly. Will also check out that variable.

Thanks so much dude!