Hello fellow camper.
I was working on my twitch api , and i’m faced to a problem I have no idea how to solve :
I’m using a variable to stock all the JSON awnser from the api, but since it’s an asynchronus event, I can’t manage to fire the function on document.ready : I get an error telling me how the variables are undefined.
Note that is I use a button to fire the api function rather than the document.ready function it works perfectly.
Here’s what the part of my code that poses problem looks like :
var lives = ["nat_ali","krayn_live","streamerhouse","merry","freecodecamp"];
var streams = lives.map((val) => {
return $.getJSON("https://wind-bow.glitch.me/twitch-api/streams/"+val+"?callback=?");
});
var users = lives.map((val) => {
return $.getJSON("https://wind-bow.glitch.me/twitch-api/users/"+val+"?callback=?")
});
$(document).ready(function(){
$.when(streams).then(getStreams(getUsers) );
});
link to the codepen : https://codepen.io/Hadrienallemon/pen/ddBOxB
(you can see if you click the test button at the bottom on the page how the api call works perfectly ? )
would anyone have any idea about how to solve this ?
Thanks in advance !