I thought I got callbacks, but I can't get them to work in this little problem I set up to get my head around the concept :
I have a list of Twitch.tv streamers (I got sidetracked working on a freecodecamp problem) and an empty array :
var players = ["imaqtpie", "imaqtpie"]; //this guy's always online. It's just easier.
var games = [];
All I'm trying to do is to get the game played by each streamer and pass it to the "game" array on page load.
I have this :
var players = ["imaqtpie", "imaqtpie"];
var games = [];
function functionUNO(callback) {
var a;
for(i = 0; i < players.length; i++) {
a = $.getJSON('https://wind-bow.gomix.me/twitch-api/streams/' + players[i] + '?&callback=?');
games.push(a);
};
callback();
};
function functionDOS() {
console.log(games);
};
$(document).ready(function(){
functionUNO (function() {
functionDOS();
});
});
which correctly returns the json in my array, but I can't figure out how to get only the game played.
I tried
var a = $.getJSON('https://wind-bow.gomix.me/twitch-api/streams/' + players[i] + '?&callback=?', function(json) {return json.stream.game});
which doesn't work, and
var a = $.getJSON('https://wind-bow.gomix.me/twitch-api/streams/' + players[i] + '?&callback=?', functionTRES);
with a separate functionTRES
function functionTres(data) {
games.push(data.stream.game);
};
which returns the game and the json...
What am I doing wrong?