HI Guys, I need your help. I’m banging my head trying to understand why the Function is not going through if/else correctly.
//Users
var userList = [“ESL_SC2”, “freecodecamp”, “OgamingSC2”, “cretetion”, “storbeck”, “habathcx”, “RobotCaleb”, “noobs2ninjas”]
var counter = 0;
//Function
userList.forEach(getStreamData);function getStreamData(){
$.getJSON(“https://wind-bow.gomix.me/twitch-api/channels/” + userList[counter] + “?callback=?”, function(data){
console.log(userList[counter]);if(data["_id"] = false){ **console.log("false: No Channel");** $("#"+userList[counter]).replaceWith("Channel Not Found"); }else{ **console.log("Live Channel");** $.getJSON("https://wind-bow.gomix.me/twitch-api/streams/" + userList[counter] + "?callback=?", function(streamData){ if(streamData.stream == null){ **console.log("No live stream");** $("#"+userList[counter]).replaceWith('Offline <i class="fa fa-television twitchUserOffline" aria-hidden="true"></i>'); }else{ **console.log("Live Stream");** $("#"+userList[counter]).replaceWith('Live <i class="fa fa-television twitchUserLive" aria-hidden="true"></i>'); } }); } counter = counter + 1; });
};
I use console.log to show me how the code is being executed, and it is jumping around and not executing in order that I would expect for if/else.
Console details:
“ESL_SC2”
“Live Channel”
“freecodecamp”
“Live Channel”
“OgamingSC2”
“Live Channel”
“cretetion”
“Live Channel”
“storbeck”
“Live Channel”
“habathcx”
“Live Channel”
“RobotCaleb”
“Live Channel”
“Live Stream”
“noobs2ninjas”
“Live Channel”
“No live stream”
“Live Stream”
“No live stream”
“No live stream”
“No live stream”
“No live stream”
“No live stream”