Doing json api (intermediate project)

Doing json api (intermediate project)


i dont understand where m going wrong…its only a partial code…after showing the online channels…it repeats the RobotCaleb in the array instead of showing all distinct names and their status

var streamers=[“HardlyDifficult”, “ESL_SC2”, “OgamingSC2”, “adobe”, “cretetion”, “freecodecamp”, “storbeck”, “habathcx”, “RobotCaleb”];
var logo="";
var name="";
var status="";
var URL="";
var channel=“”;
var streams=“”;

for (var i = 0; i < streamers.length; i++) {
var channelURL=channel+streamers[i]+"?callback=?";
var streamsURL=streams+streamers[i]+"?callback=?";
if ( {

function getOnline(on){;;;;
function getOffline(off){
function setData(){$(".content").append("




Twitch problem when clicking on buttons

Change var to let in the following code.

	var channelURL=channel+streamers[i]+"?callback=?";
	var streamsURL=streams+streamers[i]+"?callback=?";


its working now…thanx a lot for helping me 2nd time


btw what is difference b/w “let” and “var”?


Variables defined with var are known throughout the function where they are defined. (Global to the function), where as variables defined using let is only known in the block of which they are defined. let “locks in” the value of the variable at the time it is used from then on to create closure over the getJSON calls. Because getJSON is asynchronous, a var declaration would just have the last value of the variable in the for loop. In your case, streamsURL (the one used in your 2nd getJSON call) would have used the last index for i at the time the for loop finished, so all the remaining calls would have been for “RobotCaleb”.


Thank you so much sir !


Also, I think this video explains the differences between var, let and const very well:

I found that as a beginner, you are only introduced to var in most coding tutorials, but it seems that it is very useful to know all three of them.


yupp its helpful…thanx