I’m just about done with the project but I can’t get the page to display whether the channel is online or not. I think the problem may have to do with the getjson call in the middle of the other getjson call, but I don’t know any other way to do it. The stream information doesn’t appear to be in the first json call so I need to make another one, but when I do using the same strategy as the first, all the channels come back as undefined with null status on the stream. Thanks. Here is my javascript code. Sorry if the code is a little hard to read, codepen often formats the code oddly and I have trouble counteracting it.
$(document).ready(function() {
var url2 = " https://wind-bow.glitch.me/twitch-api/channels/";
var url3= "https://wind-bow.glitch.me/twitch-api/streams/";
var userNames = ["ESL_SC2", "OgamingSC2", "cretetion", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas","Freecodecamp"]
for(var i = 0; i<userNames.length;i++){
$.getJSON(url2+userNames[i],function(data){
var onlineStatus;
$.getJSON(url3+userNames[i],function(data2){
if (data2.stream === null){onlineStatus="OFFLINE"}
else{onlineStatus = "ONLINE"}
$('#channelInfo').prepend("<br><img src='"+data.logo+"' class = 'left' style= 'width:120px; border-radius:100%; bottom:100px;' > <br>");
$('#channelInfo').prepend("<ul class='center' style='font-size:50px;'>"+ "<a href ='"+data.url+"'>" + data.display_name +" </a>"+onlineStatus+ "</ul>");
if(data.status !== null){ $('#channelInfo').prepend("<ul class='right' style='font-size:20px;'>" + data.status +"</ul>" );
}
$('#channelInfo').prepend("<hr>")
});
});
}
});
And here is the link to the codepen