0

I am doing the Freecodecamp Twitch TV project where I show if 9 streamers are online. I use this array to store the streamers:

Codepen: https://codepen.io/Mike-was-here123/pen/MOmKzO

var streamers = [
    "ESL_SC2",
    "OgamingSC2",
    "cretetion",
    "freecodecamp",
    "storbeck",
    "habathcx",
    "RobotCaleb",
    "noobs2ninjas"
  ];

I use these two API's, I used a for loop which I explained later.

Channel/streamer details:

"https://wind-bow.gomix.me/twitch-api/channels/"+streamers[i]+"?callback=?"

Stream details (to check if their streaming)

"https://wind-bow.gomix.me/twitch-api/streams/"+streamers[i]+"?callback=?"

I used this code to access these API's

for (var i = 0; i < streamers.length; i++) {
    var streamStatusApi =
      "https://wind-bow.gomix.me/twitch-api/streams/" +
      streamers[i] +
      "?callback=?";


    var channelApi = "https://wind-bow.gomix.me/twitch-api/channels/" +
      streamers[i] +
      "?callback=?";


    $.getJSON(streamStatusApi, function(data) {
      $.getJSON(channelApi, function(data2) {
       if(data.stream == null) {
        // here i pushed something into the html based on stream status
       } 

       else if (data.stream == true) {
          // here i pushed something  into based on stream status.
        }
      });
    }); // $.getJSON for stream status
  } // for loop

So why is only noobs2ninjas's stream status being displayed on the html? Basically the last name in the array.

Sam Hanley
  • 4,707
  • 7
  • 35
  • 63
Leed
  • 263
  • 2
  • 4
  • 11
  • Possible duplicate of [$getJSON and for loop issue](https://stackoverflow.com/questions/15347750/getjson-and-for-loop-issue) – Bertrand Martel Nov 13 '17 at 23:05
  • So how am i able to access both API's within this loop? I dont know if it would be global if i did two separate ones. – Leed Nov 14 '17 at 00:20

0 Answers0