Help with Tweet button in Random Quote Machine challenge

Hi there,

I’ve been working on the Random Quote Machine challenge and have a working machine - apart from the tweet quote button.

I’ve been scouring the web for hours and can’t seem to find a solution that works. Currently the closest I have come is tweeting a random quote (not the same as the one displayed on my page) that also includes formatting that I obviously don’t want. i.e. the h3 and italic bits. I know why what I have done does this but it’s the closest I can get!

I’m not sure if the problem is how I’ve created the quote machine, or if it is just that I can’t find a way to reproduce what is being displayed in my quote machine and storing in a variable or suchlike.

Any help would be massively appreciated!

My pen:

Thanks,
Stuart

Feel free to see how I did it:

1 Like

@StuJ89…I initially struggled with this a bit myself since the Twitter developer documentation is lengthy and complex. However, in the end I just looked at the HTML generated by the ‘Share on Twitter’ option of the Share button at the bottom of the CodePen page. I hope this helps and feel free to look at my Random Quote Generator if you get stuck.

1 Like

Your random quote is being generated inside the .html() method. Try assigning it to a variable before setting it as the content of the ‘quote’ class. Then you can set the textToTweet variable to the same quote (using the variable from earlier) instead of generating a new quote for the textToTweet variable.

2 Likes

Thanks everyone, finally got it working!

Basically I changed what I was tweeting to -
var tweetJoke = $(".quote").text();

and all the problems were solved!

I didn’t know how to call the quote as it appears on the page but that solved everything.

Thanks a lot for all your replies. :slight_smile:

2 Likes