I'm trying to create a twitter button that allows the user to share the results of a random quote generator.
This is my html:
Quote Machine
<button onclick="generateQuote()">Click me</button>
<p id="quotes"></p>
<p id ="twitter"></p>
And this is my javascript:
var quotearray =["Always be yourself","Stay in the moment","Be merry"];
var pickAQuote = function () {
var newquote = quotearray[Math.floor(Math.random() * 3)];
var noquotes = newquote.replace(/['"]+/g, '');
return noquotes;
};
function generateQuote() {
var newquotes = pickAQuote();
document.getElementById("quotes").innerHTML= newquotes;
document.getElementById("twitter").innerHTML ='<button onclick=' +
'"https://twitter.com/intent/tweet?text=' + newquotes + '";>Tweet
This</button>';
}
So the idea is that whatever the randomly generated quote is, the user can then share that quote on twitter. But I can't get it to work! Any advice would be much appreciated!