Tweet button quote generator Help

I have no idea where to start and all of the forums that I looked at about this subject are specific to their code. Can someone point me to the right direction. Here is what I have so far

That’s funny, I’ve answered this question like 4 times in the last couple days including this morning.

Anyway, this is the URL you will need to use:[yourQuote]

Assuming you have the quote as a variable, you can easily add it to the url with a template string:


You will need to open this link when they click on your tweet button, so find a way to put that link as the tweet button’s href.

Example: Wonderful Message

Hey, I checked your code, you’re almost there! I see you got the tweet button on your page, and it’s going well.

I don’t think you are aware of what a template literal is, you have this as your link:'${getQuote()}');

That is basically an exact string. You can use the + operator to add a variable to a string, so that would be like this:'' + getQuote());

I used what is called a template literal. Template literals allow us to use ${} to insert variables into a string. To use template literals, you must use backticks not a singlequote. What you had would be a great template literal, but change the single quotes to a backtick:`${getQuote()}`);

Once you get that, your link will be mostly good. There are a couple other slight problems that you can change to make your code work better.

You don’t need to use Javascript to open the window like you are doing:

$("#tweet").on("click", function(){ `${getQuote()}`);

You can modify your existing tweet button’s href inside the getQuote function. Get rid of the tweet button’s click handler, it is a button already. Move your logic to the bottom of getQuote. You can simply modify your twitter button’s href with the new link, and the variables are there for you since you are inside your getQuote() function:

$('#tweet').attr('href', `${randomQuote} by ${randomAuth}`);

Make sure you add target="_blank" to your button, and you have a working solution, congrats!

You can see the working changes I made here:

1 Like

I got it to work Thank you! and thank you for taking the time out of your day to help me out, it is much appreciated :pray:

1 Like