Random quote machine - Tweet issue

Random quote machine - Tweet issue
0.0 0

#1

Hi everyone,

I’ve got my quote machine producing quotes, but for some reason when I hit the twitter button, twitter opens to tweet, but the box doesn’t populate with my quote. Could someone take a look? Thank you!!!

Will Ferrell Movie Quote Machine

here’s my button -

 <button onclick="newQuote()">New Quote</button>

this is the code for my twitter function:

$(document).ready(function () {
  $('#twitter').on("click", function () {
    var tweetQuote = $('quotes').text();
    if (tweetQuote.length > 140) {
      alert("Too many characters!")
      }
      var twitterURL = 'https://twitter.com/home?status=' +encodeURIComponent(tweetQuote);
      window.open(twitterURL, '_blank');
  })
}); //end ready

#2

Your code has two main issues.

#1) The following line of code assigns a blank string to tweetQuote. Why? Because there is no such element as quotes. You may want to review how to select a specific element based on the id attribute with jQuery.

   var tweetQuote = $('quotes').text();

#2) Not sure why you thought you could use the below twitter url to accomplish what you were wanting to do. You can not just use the main twitter home page and put something on the end of the status parameter of the query string.

Instead, you need to use a Twitter API such Web Intent to pass the quote to twitter.


#3

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#4

Thank you!! I will look into your suggestions and let you know how it went - most likely after work this evening.

Thanks!!


#5

thank you for your help!! I was able to figure it out and now it works. I have a little clean up to do, but it is working!