Random Quote Machine - Twitter

Hi everyone,

I’m working on the Random Quote Machine challenge, but can’t seem to get my tweet button to work.

If I click the tweet button before I click the first button to generate a quote, the link to twitter works (although there is no quote to pre-populate the field)

However, if I click the quote button first, the tweet button’s link doesn’t work.

What am I doing wrong?

Add these after you assign the values to currentQuote and currentAuthor

console.log(currentQuote);
console.log(currentAuthor);

There is html and spaces you are adding to the twitter link you are trying to make.

You can use encodeURIComponent() to help make the link you need.

1 Like

Thank you br3ntor, that helped me see what I was doing wrong. To fix it, I used .text() to take the string contents inside the <p> element and use them to pre-fill the input for the tweet. Also used .hide() and .show() to hide the tweet button until there’s a quote in the <p> element.

I’ll have to read up on encodeURIComponent() as it’s new to me, but thank you for the suggestion.

Edit: Also deleted the currentQuote and currentAuthor variables as I didn’t need them anymore.