Random Quote Generator - JS Button

I have completed the challenge.

https://codepen.io/deadman875/pen/zYxJJQE

However, it requires the tweet button to be an anchor link with a href pointing to the twitter intent page. It won’t accept the javascript button I’ve built. How do I carry the quote into html to call the link with the values of the quote?

<a> element should include the "twitter.com/intent/tweet" path in it’s href attribute to tweet the current quote.
Since you set href='#blank' so you need to set it to href="twitter.com/intent/tweet".

Thanks. I see that bit. I’m just having trouble getting it to send my current quote to twitter when I set the href to the webpage. With the JS button, I can use a variable to store the quote and send that variable along with the website call. If I link directly to the intent in the href, then the twitter box is blank. I’m wondering if there’s a way I’m missing to use JS variables in an HTML property value (or something else I’m missing).

I’m not 100% sure what you are asking;
but this route would remove your tweetQuote function and use _blank to open a new tab.
What you had works for me, and opens a twitter box with a push to Tweet option (WIN/Chrome):

HTML:
<a href='' id="tweet-quote" class='button' target='_blank'> //removed onclick & added target for new tab

JS:
lines 19-22 replaced with:

document.getElementById('tweet-quote').href = `https://twitter.com/intent/tweet?text=${tweet}`
}
//replaces onclick function

1 Like

:man_facepalming: That did it. Thank you. I was clearly overthinking it. Forgot that I can simply control the href value with JS.