I am on using Twitch api to check if selected channels are online or offline. Having a weird bug. Code works only when debugging the script in dev tools. Am I missing anything?
$(document).ready(function() {
var channels = ["OgamingSC2","sheevergaming", "ESL_SC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
for (var i = 0; i < channels.length; i++) {
$.getJSON('https://api.twitch.tv/kraken/streams/' + channels[i] + '?callback=?', function(data) {
if (data.stream) {
$('.wrapper li').eq(i).css('background-color', "blue");
} else {
$('.wrapper li').eq(i).css('background-color', "red");
}
});
};
})
Here is the full code http://codepen.io/nikasv/pen/GqRMXq