Twitch project (PROBLEM?) (SOLVED by bubulblu)

Hello, I have recently ‘finished’ the twitch project, and by this I mean fulfilled the user stories.

However, upon looking at all the other projects, it’s clear, my code is very different, as I’m not using functions to carry out my processes. The entire project is wrapped in a loop, extracting and displaying the information.

I was wondering, whether or not my project is missing the point or if my solution is just different?

Also, an issue I’m yet to resolve is getting the name of the ‘closed’ accounts to render into the allocated div.
If you can solve this problem, you’re awesome.


First of all, you did a great job : it is working !

You could certainly refactor some part of your code into functions. For example functions to generate the onlineHtml or offlineHtml strings. You will be able to see when to do it the more you keep on coding.

Secondly, for the ‘I am awesome’ challenge, you can do the following :
var name = data.display_name || array[i]

1 Like

Thanks a lot for taking the time to respond!

Yeah, i figured. Maybe the reliance on for loops and if statements is just a sign of my infant age in coding :joy:

Unfortunately this didn’t work, so you are by this particular metric ‘not awesome’, haha.

haha, you right. I am not so awesome.

Don’t worry, the more you code, the more you will see how to optimize your code. Just keep on coding !

I found a solution for the problem. The solution involves an advanced topic of javascript : closure. Do you know what it is ?

I haven’t come across this, If you explain, or point me to the solution, I’ll be sure to research it.

I’m aware, it’s something to do with being passed the loop, therefore it has missed the opportunity to pick up array[i].

Excuse me, I wrote Closure instead of Immediately Invoked Function Expression (IFFE).

IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined.

Check this links :




The idea is that you can pass the array[i] as a parameter, and give this parameter a name like channel when you define the IIFE function.

Oh man, can’t seem to get this working, think it’s a little out of my scope!

Don’t worry, if you stick around it will come.

Here is what I did :


//here goes your code of $.getJSON(). All of it


Then you can pass in the array[i] as a argument. Because it is an IIFE, you pass the argument like this :


//here goes your code of $.getJSON(). All of it

})(array[i]); <<<<< HERE

And to be able to access it, declare a parameter for the function :

(function(channel){ <<<<< HERE

//here goes your code of $.getJSON(). All of it


When you want to display the name, just write channel.

Let me know how it goes.

1 Like

Wow, that worked, you are officially certified ‘awesome’. Thanks a lot for your help man, I hope one day i’m able to solve one of your issues! Long road ahead, but really appreciate this!

My pleasure :slight_smile:

Happy coding.