Quote Machine - decoding the text to tweet

Dear Community,

I am building my quote machine, it still needs some polishing
https://codepen.io/Kosiada/pen/xWdVLb

But before I’ll get there I try to figure how to get
textToTweet.
I initialized the variable and then ascribed it to d.quote and console.log it inside of the function setQuote. It gives the same quote as generated. Great! But it doesn’t work outside of the function.
How can I get textToTweet? Shall I rebuild the setQuote function?
Thank you in advance!

mebbe try…

"window.open('https://twitter.com/home?status=')"

i haven’t done this one yet, so not too sure :stuck_out_tongue:

Hey, thanks. That is the next step. But I need variable textToTweet to set into the url after status=…
And I don’t know how to do this.

mebbe…

inside your setQuote(d) function, below the line that says
q.innerHTML = d.quote;
… add a line that says…
textToTweet = d.quote;

then make a new function like…

function outgoing()
{ var url = 'https://twitter.com/home?status=' + textToTweet ;
  window.open(url);
}

and then change your html button to use the new function…
onclick=" outgoing()"

again, i haven’t tried this, but it should be close?

Thanks again :slight_smile:
It works, but my problem remains unsolved.
I did what you recommended, but when I tweet, the text to be tweeted is ‘undefined’.
That is the issue that I faced from the beginning. I think it’s something related to the global/local scope.
d.quote gives the value of the quote only within the function setQuote. Outside of it gives ‘undefined’.
Any idea, how can I fix this?

got to escape / encode the text mebbe?
here is a sample, with text to test…
Tweet-pen

Hey Xiija,
thank you very much. It was very helpful. I will build my quote machine from scratch using a different API. The one I used seems to stop working. I will let you know, when my machine is working fine.

Edit March 24th
I built the machine from scratch https://codepen.io/Kosiada/pen/xWdVLb
it works, but when a quote has ’, : , [
the tweet stops where the special sign appears.
And html tags are included , etc…

How to get rid of the signs and twee the special signs?

Edit March 24th, later
I fixed it using $("#quote").text().trim() + “%0D%0A” + $("#author").text().trim();

Pretty proud… :wink: