I am trying to push a local variable out into a global array. But for some reason the array comes out as empty.
follows.push(data2.follows[i].channel.display_name) is not pushing out the display_names to the follows array.
The JSON function is being called in. When i console.log(data2.follows[i].channel.display_name) the console logs out a populated array.
var follows = []; // EMPTY GLOBAL ARRAY I AM TRYING TO POPULATE//
var status, info;
var fcc = {
fccstatus: function(status, info) {
$.getJSON('https://api.twitch.tv/kraken/streams/freecodecamp?callback=?', function(fccdata) {
if (fccdata.stream === null) {
info = "Offline",
status = "offline";
} else {
info = fccdata.stream.game,
status = "online";
}
(function() {
$.getJSON('https://api.twitch.tv/kraken/channels/freecodecamp?callback=?', function(fccdata1) {
var fcclogo = fccdata1.logo,
program = fccdata1.display_name,
name = fccdata1.display_name,
fccbanner = fccdata1.profile_banner,
description = fccdata1.status;
html = '<div style="background-image: url(' + fccbanner + ')" class="row ' +
status + '"><div class="col-xs-2 col-sm-1" id="icon"><img src="' +
fcclogo + '" class="logo"></div><div class="col-xs-10 col-sm-3" id="name"><a href="' +
fccdata1.url + '" target="_blank">' +
name + '</a></div><div class="col-xs-10 col-sm-8" id="streaming"><span class="hidden-xs">' +
description + '</span></div></div>';
$("#fcc").append(html);
});
$.getJSON('https://api.twitch.tv/kraken/users/freecodecamp/follows/channels?callback=?', function(data2) {
for (var i = 0; i < data2.follows.length; i++) {
follows.push(data2.follows[i].channel.display_name);
}
});
})();
})
},
};
$(document).ready(function() {
fcc.fccstatus(); //FCC VAR containing the JSON callbacks //
});
Aucun commentaire:
Enregistrer un commentaire