Trying to set my Tweet link/button to pass the quote information to the tweet. I plan to pass the $.param(quote) but just wanted to pass the variable ‘quote’ for now that was set in the getJson call. However in my code it says that ‘quote’ is undefined.
$(document).ready(function(){
var qodAPI = "https://random-quote-generator.herokuapp.com/api/quotes/random";
var quote;
var author;
function displayQuote(data){
quote = data.quote;
author = data.author;
$("#quote").html(quote + "<p>— " + author + "</p>")
}
function newQuote(){
$.getJSON(qodAPI, displayQuote);
}
function tweetQuote(){
$('#tweetButton').attr("href", "https://twitter.com/intent/tweet?text=" + quote)
}
//new quote when page loaded.
newQuote();
tweetQuote();
$('#quoteButton').click(function(){
newQuote();
})
});