Skip to content

Instantly share code, notes, and snippets.

@waldothedeveloper
Created May 18, 2018 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waldothedeveloper/501266d67a3d61458944f172a8cc1dc2 to your computer and use it in GitHub Desktop.
Save waldothedeveloper/501266d67a3d61458944f172a8cc1dc2 to your computer and use it in GitHub Desktop.
The full javascript file about the freecodecamp quote app
$(document).ready(() => {
console.log('ready!');
$("i#tweet-icon").on("click", () => {
let quote = $.trim($("#quote").text());
window.open(`https://twitter.com/intent/tweet?text=${quote}`);
});
let endpoint = 'https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?';
let getRandomQuote = () => {
$.getJSON(`${endpoint}`, (data) => {
$("#quote").html(`<i class="fas fa-quote-left"></i> ${data.quoteText} <i class="fas fa-quote-right"></i>`);
//Checking if the quote does not have an author
if (data.quoteAuthor !== "") {
$("#quote-author").html(`${data.quoteAuthor} at <a href="${data.quoteLink}" target="_blank" class="card-link">forismatic</a>`);
} else {
$("#quote-author").html(`Unknown at: <a href="${data.quoteLink}" target="_blank" class="card-link">forismatic</a>`);
}
});
//Create a tweet function
function tweetQuote() {
window.open(`https://twitter.com/intent/tweet?text=${data.quoteText}`);
}
$("#tweet-icon").on("click", tweetQuote);
};//end of getRandomQuote
$("#quote-button").on("click", getRandomQuote);
});// end of document.ready
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment