Random quote machine twitter

Hi, I’m working on the random quote machine project and I’ve almost completed it except for one issue when I go to tweet a quote a separate twitter window opens with every quote I’ve seen before during that particular session.

I’m generating my quotes from a forismatic api and when I view the console all the api JSON request objects from previous quotes are listed.

I’m guessing I need a delete or reset on each on click for a random quote so old ones do not open twitter windows but I can’t find anything from googling.

Thanks for any help
Ed

Could you post your code or a link? It’s a bit hard to address without being able to see how it is working.

You shouldn’t have to do a reset or delete, but it just depends on how you are pulling those quotes in to update the DOM.

1 Like

The easiest way to achieve this is probably to store the last quote in a global variable and use that as the tweet text.

Hi, sorry about the delay here is the link

Okay, yeah, I totally see the issue here. I have played around with it for a bit, and haven’t been able to solve it either, yet! Sorry!

There is only one thing that makes sense to me, although I am sure someone else might know with more confidence what the issue is. I wonder if the event handler on your twitter button is bound to that first quote object that is created. Therefore, no matter how many times the quote object is refreshed to a new one, the tweet button is still holding reference to the text in that original object.

I do wonder if @janschreiber has something, with creating a variable outside the scope of that event handler so that you can pass the text of the quote in. I think this may be a closure or binding issue…

1 Like

I had a similar (but different) issue with my quote machine as well. Instead of it keeping all of my quotes in the new tweet, it would run make tweets equal to the number of times I had gotten a quote, so it became an issue rather quickly.

Mine was resolved by creating global variables, and then using those to tweet the quote + author.

I’m trying something similar with this pen, but I’m not having the best luck ATM.

1 Like

Thanks JSmurf, robgaston1 and janschreiber, I’ll try and alter it with global variables.

I found the answer on Stack Overflow had to add unbind
$(’.twitter’).unbind(“click”);
before the onclick.