Random Quote Project doubt

Random Quote Project doubt
0.0 0


Hey i want to know, how a user can tweet out a random quote directly?


Twitter has a certain URL built for this:


As an example, open this in your browser: https://twitter.com/intent/tweet?text=To Code or Not to Code

To do this in your project, you will need to have your quote as a variable. Then you will simply need to append the variable to the twitter url string and put that link in a button.

A short example:

const button = document.querySelector('button')

let twitterURL = 'https://twitter.com/intent/tweet?text='

let quote = await getQuote()

button.href = `${twitterURL}I really liked this quote "${quote.text}" by ${quote.author}`


you can also add formatting if you useā€¦
encodeURI or encodeURIComponent ?

var  textToTweet = "Roses are ...";
var author = "You";
var url = "http://something";
 url += encodeURIComponent('Quote: \n"' + textToTweet + '"\n ~' + author + "\n");