Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Random movie quote generator jquery ajax call to api and tweet button to tweet out quote.
//get the quote api information with Ajax
var bgCols = ['#2e67f7','#ea5c30','#38b582','#683a20','#59357d', '#555'];
function getQuote(){
var num = Math.floor(Math.random()*6+1);
url: "",
type: "GET",
data: {},
dataType: "json",
beforeSend: function(xhr) {
xhr.setRequestHeader("X-Mashape-Authorization", "xYdGlgmLb6mshjBkNyNcbyQpGZuLp17o5c4jsnMmdf7VIAQut0"); // My Mashape key
success: function (data){
$('.twitter-share-button').attr("href",''+ encodeURIComponent(data.quote) + encodeURIComponent(' Movie: ') + encodeURIComponent( + encodeURIComponent(' #FreeCodeCamp #RandomQuoteGenerator') + '&via=Nicki_Hastings');
$('.container-box').css('background-color', bgCols[num]);
error: function(err) { console.log("Failure!..."); console.log(err); }
$("#nextQuote").on("click", function(e){
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment