Hey folks, in the process of applying for new jobs and want to make sure my portfolio isn’t all janky. For some reason I cannot get my Random Quote Generator working. It looks like the site that originally hosted where I pull the quotes from changed, but even after changing it to the correct site and updating the key I’m unable to get a random quote to display. Everything else looks like it’s working fine.
Here’s the JS code:
$(document).ready(function() {
// Loads quote on page load
getQuote();
$("#getQuote").click(getQuote);
});
function getQuote() {
$(document.body).css('background-color', colors[Math.floor(Math.random() * colors.length)]);
$.ajax({
type: "POST",
url: "https://andruxnet-random-famous-quotes.p.rapidapi.com/?count=10&cat=famouss",
responseType: "json",
success: function(response) {
showQuote(response);
$('#tweet-quote').attr('href', 'https://twitter.com/intent/tweet?text=' + encodeURIComponent('"' + response.quote + '" - ' + response.author));
},
error: function() {
alert('Error retreiving quote');
},
beforeSend: setHeader
});
function setHeader(xhr) {
xhr.setRequestHeader("x-rapidapi-key", "sUHZ623ia5mshGZPh9XMvWs06Ltcp1zBgy1jsnyx6wQE0Wwnxl");
xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Accept", "application/json");
}
}
function showQuote(response) {
console.log(response);
$('#quote').text(response.quote);
$('#author').text(response.author);
}
var colors = [
'#4286f4',
'#f4417a',
'#58f441',
'#41f4f4',
'#f1f441'
]
Any help would be greatly appreciated.