Hit a roadblock and need a little help to keep up

Hit a roadblock and need a little help to keep up
0

#1

Hello fellow campers,

After some time out of FCC due to vacations and etc, i now have the time to continue this project and after some modifications to my initial code, i’ve hit a roadblock and can’t seem to pass it.

My code:

//--------------------------------------------------------------------------------------------------------------------------------------------------
var channels = [“ESL_SC2”, “OgamingSC2”, “cretetion”, “freecodecamp”, “storbeck”, “habathcx”, “RobotCaleb”, “noobs2ninjas”];
var div;
var idDivName;
var br;

for (var item in channels) {
$.getJSON('https://api.twitch.tv/kraken/streams/’+channels[item]+’?callback=?’, function(data){

    div = document.createElement('a');
    div.setAttribute('id', idDivName);
    br = document.createElement('br');
    
    console.log(data);

    if(data.stream == null){
        div.innerHTML = "Offline: " + data._links.channel;
        document.body.appendChild(div);
    }else {
        //link = data._links.channel
        div.innerHTML = data.stream.channel.display_name + " is online and streaming: " + data.stream.channel.game;
        document.body.appendChild(div);
        document.body.appendChild(br); 
    }
})

}

//--------------------------------------------------------------------------------------------------------------------------------------------------

And now i want to be able to click a streaming channel and got to the link that the api provide, but i can’t create that link.

Can you help me?

Thanks in advance and happy coding =)


#2

var a = document.createElement('a').href= data._links.channel;

a.setAttribute('target', '_blank');
To open in new tab


#3

Sorry for the long, very long, feedback but it worked. Thank you very much :smiley: