The machine works, but I cannot populate the new tweets created with the Tweet button in Codepen.
Here is my Codepen; I have not worked a lot in the CSS yet.
What it should do: the Twitter button should contain a link to the random quote machine if the user has not generated a random quote. However, if the user clicks on the New Quote button and then the Tweet button, the tweet should contain the quote, the author and the link to the quote machine.
What it does: the quote machine generates random quotes (correctly), but, after clicking on the tweet button, the tweet contains only a link to the quote machine, not the displayed quote.
The console throws this error:
Uncaught TypeError: Cannot set property ‘href’ of null
at Object.tweet (pen.js:28)
at HTMLButtonElement. (pen.js:36)
Then I entered:
document.getElementById("tweet") and the console returns
null, which makes sense.
However, when I tested the quote machine locally (in my PC), everything worked as intended. When I entered
document.getElementById("tweet") the console returned:
<a id="tweet" href="https://twitter.com/intent/tweet?text=Fake+quotes+machine" class="twitter-share-button" data-size="large" data-show-count="false" target="_blank">Tweet</a>
Why is there an error in Codepen?
Thanks in advance for your help
EDIT: Pardon me, if that matters, when I test the html file locally, I put
<script src="random quote machine.js"></script> just before the closing