Reputation: 511
I am using twitch api json files with javascript functions and I wanted to see if I could write an if else statement with a part of the json file being tested. Here is the link to the json file.
So now that we have the json file let me explain what I want it to do. I want to select the "stream" part of the json file and want to test it in a javascript. If "stream" == null then say Offline but if "stream" != nul then say online.
Here is the function I have so far:
$.getJSON("https://api.twitch.tv/kraken/streams/"+ twitchName +".json?callback=?", function(c){
if (stream == null) {
document.getElementById("live").innerHTML="Offline";
};
else{
document.getElementById("live").innerHTML="Online";
}
});
What am I doing wrong? Can someone please help? Thanks.
Upvotes: 2
Views: 2240
Reputation: 4057
Try this:
$.getJSON("https://api.twitch.tv/kraken/streams/"+ twitchName +".json?callback=?", function(c){
if (c.stream == null) {
$("#live").html("Offline");
} else {
$("#live").html("Online");
}
});
Upvotes: 2