Help with random quote machine tweet button

Help with random quote machine tweet button
0

#1

I am having trouble with my RQM tweet button.
I am brand new to coding so I am trying to do this project as simply as I can while meeting the criteria.
I have looked at others’ projects but they were beyond my abilities.

here is what I have so far

I can get a twitter window to open but haven’t figured out how to add a variable to the link to open whichever quote is currently displayed.

Thanks in advance,
Allen


#2

Hi lonies87,

You could store the quote in a variable and then add that variable to the twitter url.

var curQuote = quotes[randomNumber];
https://twitter.com/home?status=” += curQuote

Also, I’d recommend using the FCC gitter chat. Usually you can get quick replies there.


#3

You can also access it directly off the page. You put it on the page with the selector document.getElementById('quoteDisplay').innerHTML - and that works both ways. Try:

function tweetQuote(){
  console.log(document.getElementById('quoteDisplay').innerHTML);
  window.open("https://twitter.com/home?status=");
}

and you’ll see it in your console.

Though, I found this a more direct way to tweet:

window.open("https://twitter.com/intent/tweet?text=" + text);

Just sub in your selector for my variable text.


#4

I have tried this soln and the one above but I still can’t get the quote in tweeter.

When I put the tweetQuote function in the newQuote function, I don’t get any link when clicking tweet button.
When I make them two separate functions and put quoteDisplay after the twitter url, I get the twitter window but the text box reads “[object HTMLDivElement]”

I have tried different ways to assign the quote to a variable then call for it in the tweetQuote function but I can’t figure it out.


#5

When I plug the selector I suggested into your tweet function, it works for me:

function tweetQuote(){
  window.open("https://twitter.com/home?status=" + document.getElementById('quoteDisplay').innerHTML);
}

Let me know if this still doesn’t work for you.


#6

This time it worked! Thank you so much


#7

Thank you, this also helped me with my project :slight_smile: