Tweeting random quote

Hi,

For tweeting the random quote, is an API needed and do we need to send the tweet to a server?

I went through the forum and i have seen some posts where people have used a URL i.e (https://twitter.com/intent/tweet?text=)

That’s the link provided by the challenge instructions. It will work to pass the tests, and it will work to take you to the twitter “tweet” page, but it will not include the text from your random quote. :slight_smile:

Thanks for the quick response. I did not notice it, my bad. I have just tried to do this but my code keeps opening a blank page. A snippet of my code is below. Can’t figure out what i’m doing wrong

$(’#tweet-quote’).click(function() {
window.open('https://twitter.com/intent/tweet?text=’+ document.getElementById(“text”).innerHTML);
});

Are you building this in CodePen? Or do you have a live version I can view elsewhere?

https://codepen.io/Layoooo/pen/jOWNjZB

Perfect!

Okay, after playing with it here’s what I’ve discovered. You have two errors to correct before that link will work:

  • By using the quote text, you’re including the whitespaces " " which is breaking the link and resulting in about:blank
  • Using “innerHTML” is including the <p> tags in the link, which doesn’t prevent the link from working but means my tweet text includes them.

thanks for the response. shouldn’t the link be in quotes? not sure i understand what you mean by quote text

By “quote text” I meant the text of your quote.
The stuff you get with document.getElementById("text").innerHTML

right, i see.

document.getElementById(“text”).innerHTML is not empty though it actually contains a quote. Maybe i need to take a different approach. Thanks for the help!

No, it’s not empty.
But it includes the spaces between the words.

So your url becomes https://twitter.com/intent/tweet?text=This is a quote
URLs can’t have spaces in them - spaces are represented with %20.

@Layooo Try using document.getElementById('text').textContent instead of innerHTML.

oh wow this works. Thanks! I thought ‘innerhtml’ and ‘textContent’ pretty much did the same things

1 Like

textContent actually returns all the html removed content

You can refer this :wink:

Plesae mark this as solved if you feel like it.