Twitch.tv project. Please help to find error

Twitch.tv project. Please help to find error
0

#1


after first call printStreamers str is empty, why?


#2

First u have this logic in code:

if (data.stream === null){
             ....
            }
if ("game" in data.stream){
...
}

so u getting error when is data.stream === null, that game prop cannot be accessed in object that is null
On other side object that u want to refer is not null, it is undefined
so u may write like this:

if (!data.stream){

}
else if (“game” in data.stream){

}

Then u got empty string cause getJSON is async operation
U have here nice but on other side old explanation
http://javascript.info/tutorial/events-and-timing-depth

TL;DR;
Your console.log is happening before getJSON is done cause async mode
So u want to move your lines:

$(".streamers").html(str);
console.log('my string: ’ + str);

inside getJSON function

Also if u don’t want to your result concatenate, reset str every time u are in getJSON


#3

Thanks, i did this job, but understend not everyone.