Help Twitch API [Javascript Asynchronous Requests]

Help Twitch API [Javascript Asynchronous Requests]
0

#1

Hello campers,
I have been having problem with asynchronous requests in the Twitch API project. I have been able to request the website and get its data. However, I am trying to update a global variable inside an asynchronous request and is not working well. I would be really glad if someone could help me with it.


#2

Have you taken a look at your console (Ctrl+Shft+I in Chrome)? You have a many errors you need to fix first. Once you fix those errors, then some of your code may work. If not, then reply back after the errors have been corrected.

One thing I will ask you is why do you have the first 9 lines of code written outside your $(document).ready(function(){?

Some of your errors are because you try to access DOM elements before the DOM has fully loaded.


#3

I was trying to experiment with $(document).ready(function(){} as I thought that maybe the asynchronous function would update the variable and just then the code inside $(document).ready(function(){} would be executed.


#4

I noticed you linked to

https://raw.githubusercontent.com/caolan/async/master/dist/async.min.js

but you are not using the library in your code.

I could be wrong, but it looks like you copied/pasted bits and pieces of others’ code and are trying figure out what the code does instead of starting from ground zero and mapping out what you want your app to do. When I see the inconsistent use of declaring variables (sometimes var and sometimes let/const), it seems like copy/paste. Also, paired with the external library link which is not used and the following line, it looks a little suspicious.

OK, now that my assumptions are out of the way, why don’t you explain a couple of things, so that we can better assist you.

  1. When the app loads, are you wanting something to display besides the texbox and “Add Twitch Channel” button? If so, describe in detail what you want to happen.

  2. When the user clicks on the “Add Twitch Channel” button, what do you want to happen? What should be displayed and where?


#5

The copy and paste parts are from another project that i asked for a camper here in the forum to help. Since I understood his code but was afraid of changing it I copied from the other project and made just the necessary changes,

  1. When the app loads, its going to show the twitchers that are already in the array all in separate boxes with Online/Offline and the game currently played.

  2. Add twitch channel is going to add a new twitcher to the array. This will reload the page with the separate boxes of the standard array + the chosen twitcher. This is going to be displayed below the search bar in the div with the id “results”.

By the way, the library was a failed attempt to control the asynchronous requests. But it failed miserably, and I forgot to take it out of the code.