Greetings,
I’m currently working on the TwitchTV API project.
So far i have been able to do two JSON queries and store each channels info into corresponding arrays.
My idea is to use a for loop to construct each channel Div element to display on page, using the data stored on each array.
The problem is that when using a for Loop, this is not executing. I’ve tried doing a basic function on the for loop for it to print the counter variable that i’m using within it and the console is not printing the variable within the For loop.
I Attach my code so you can try checking something within it.
$(document).ready(function(){
var chList = ["esl_sc2","ogamingsc2","cretetion","freecodecamp","habathcx","robotcaleb","noobs2ninjas"]
var userNames = []
var userLogos = []
var userStatus = []
var userGame = []
function users(channel){
$.getJSON('https://api.twitch.tv/kraken/users/' + channel + '?client_id=lq86w0m7fmbky1gv60cb77biorco11', function(json){
userNames.push(json.display_name)
userLogos.push(json.logo)
})
}
function streams(channel){
$.getJSON('https://api.twitch.tv/kraken/streams/' + channel + '?client_id=lq86w0m7fmbky1gv60cb77biorco11', function(json){
var status = jQuery.isEmptyObject(json.stream)
if(status !== false ){
userGame.push('')
userStatus.push('Offline')
} else {
userGame.push(json.stream.game)
userStatus.push('Online')
}
})
}
chList.forEach(users)
chList.forEach(streams)
console.log(userNames)
console.log(userLogos)
console.log(userStatus)
console.log(userGame)
for (var k = 0; k < userNames.length; k++){
console.log("Whatever")
}
//only for loop for div construction is missing.
});