Created
May 18, 2018 12:03
-
-
Save waldothedeveloper/422c9f80af8be0d3e1633f9af3f46c50 to your computer and use it in GitHub Desktop.
Making a getJSON request to the forismatic API and showing the data back in the HTML card.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(() => { | |
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>`); | |
} | |
}); | |
});// end of document.ready |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment