How to account for api data being "null" or undefined

I am on the twitch api challenge and almost done. I have not been able to figure out how to account for FCC’s stream being 'null’
I set the variable ‘check’ = data.stream which is the point where the info becomes null but it didn’t seem to work. My code is below to further illustrate

currentStatus=data.stream.channel.status;
check=data.stream;

if(check==='null'|| check==='undefined'||check===-1){
  currentStatus = 'Offline';
}

$('#info'+ i).append('<p id="info"'+i+'>'+currentStatus+'</p>');
$('#link'+ i).attr('href','https://www.twitch.tv/'+userNames);

});

});

I thought that if check came up as the string null undefined or -1 it would pass the value of ‘Offline’ to the currentStatus variable (the variable that accounts for the name of the stream), but it doesn’t seem to be doing that. Instead it’s just blank.

Here is my codepen for further clarification. As you can see only FCC doesn’t have a stream but instead of saying Offline it’s just empty space.

https://codepen.io/DebugAyem/pen/qXVvbW

Yeah I realized that check wouldn’t ever be -1 but I am still not sure if null/undefined/false are interchangeable (it seems to me now that they are not).

I did see that console error, would I approach that by using a typeOf check? (I’m still very fuzzy on type and typeOf checks and some of that console output looks like gibberish to me). I did try to remedy that by setting up the check variable(obviously unsuccesful).

I did first compare check to null and undefined (no quotes but that didn’t work so I included the quotes) therefore it seems that’s not the main issue here.

Friendly reminder that null and undefined are both falsy.

I don’t see how to work around that error because the line causing the error (I assume) is also the line that allows the channels that do have stream data to be printed to html. I looked at the console and the property comes up as null so I assumed the check variable would have accounted for that and there would be no error. I see where the error is I just don’t know how to fix it. Now I’m seeing setting currentStatus to ‘Offline’ may actually be doing more bad than good??

Dammit I hoped you wouldn’t say that. If that’s the case then would I have to rewrite my array??

edit: Nope just tried it. Ok cool thanks for the help!! Those tricky if else statements haha

1 Like