Twitch.tv JSON API project

Twitch.tv JSON API project
0.0 0

#1

Hello, I just did the Twitch.tv JSON API project, here is my code: https://codepen.io/Kestvir/pen/mmrddM
I have a few questions concerning the project.
In JS on line 62, if istead of var displayName= data3.responseJSON.message; I wanted to do displayName= deletedFollowers[i] + "custom message"; But the deletedFollowers[i] returned undefined. Why so ?
Also, on line 55 I used channels instead of users in the url: "https://api.twitch.tv/kraken/**channels**/"+deletedFollowers[i] , because users returned error 422 with one of the channels that doesen’t exist. Which of the two (channels/users) would be more correct to use when doing the call for the non existing channels/users in the url ? And what does the error 422 mean ?


#2

With regards to line 62, I think you are misunderstanding how AJAX works. The a stands for asynchronous, meaning that JS doesn’t wait for AJAX to finish before moving on. By the time the AJAX routines come back, the for loop has finished and i is now 2 (the exit condition for the for loop. If you want i to still mean what you want, you’ll have to bind it somehow.

You can confirm this behavior by adding the line:

console.log("*** i = " + i + " - " + deletedFollowers[i]);

at line 63.

There are also some other errors in the console you should address.