Hello,Everyone!
I used this API to build random quote machine. (http://www.icndb.com/api/)
Please could someone emplane to me.
I don’t understand why we need to use data[‘value’][‘joke’] ?
In another example from forismatic api (http://forismatic.com/en/api/)
it was like this data.quoteText; data.quoteAuthor;
I din’t find anything in documentation.
Complete code http://codepen.io/MrSergey/pen/BWMXEV
var bcolors = [’#29C6CD&’, ‘#FEA386’,’#07689F’,’#560764’,’#62D2A2’,’#253B6E’,’#F69D9D’,’#90F2FF’,’#6EF3D6’,’#F9A1BC’,’#CF455C’,’#470031’,’#EB89B5’,’#C7F5FE’];
var html = “http://api.icndb.com/jokes/random?exclude=[explicit]”;
var getQuote = function(data){
if(data[‘value’][‘joke’] === " "){
data[‘value’][‘joke’] = “Unknown”;
}
$(’#author’).text(“Chuck Norris”);
$(’#quotes’).text(data[‘value’][‘joke’]);
updateTweet(data);
};
function updateTweet(data) {
var thisQuote = data.value.joke;
$("#twitterShare").attr(“href”, “https://twitter.com/intent/tweet?text=” + thisQuote + "%0a— ");
}
//Calls our random quote
$(document).ready(function() {
$.getJSON(html, getQuote, ‘jsonp’);
var randomNum = Math.floor(Math.random()*15);
$(‘body’).css(‘background’, bcolors[randomNum]);
});
$(’#ch’).click(function(){
$.getJSON(html,getQuote,‘jsonp’);
var randomNum = Math.floor(Math.random()*15);
$(‘body’).css(‘background’, bcolors[randomNum]);
});