# Need help with my for loop (Twitch API project)

**URL:** <https://forum.freecodecamp.org/t/need-help-with-my-for-loop-twitch-api-project/177572>\
**Category:** General\
**Created:** [March 2, 2018, 6:11pm UTC](https://forum.freecodecamp.org/t/need-help-with-my-for-loop-twitch-api-project/177572 "2018-03-02T18:11:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MeatyJobo](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@MeatyJobo](https://forum.freecodecamp.org/u/MeatyJobo)\
**Post date:** [March 2, 2018, 6:11pm UTC](https://forum.freecodecamp.org/t/need-help-with-my-for-loop-twitch-api-project/177572/1 "2018-03-02T18:11:09Z")

</div>

I’m trying to make it so a for loop will iterate through an array of channels (each with two links) and will push the appropriate data to my html in the appropriate place.  
The ‘appropriate place’ is the tricky part.

I intended to use the current run of the for loop (i) as a string (var apiNum = i.toString) in order to push each piece of data to a specific area, through $(#“name”+apiNum). However, it appears to be pushing a random selection of intended data all to the top row (name0).

Could somebody explain to me why this is wrong and how I could do it better please? all help is much appreciated and here is the link to the full project… feel free to laugh at how not good it currently is 😅

> **[Twitch API](https://codepen.io/Jobo_v22/pen/NyoEGE?editors=1010)**
>
> Part of my course at FreeCodeCamp. Using Twitch API and JSON data to display certain channels, whether they're online and linking directly to them...

---

<div class="post-metadata">

**Author:** ![elisecode247](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/elisecode247/32/28927_2.png) [@elisecode247](https://forum.freecodecamp.org/u/elisecode247)\
**Post date:** [March 2, 2018, 6:19pm UTC](https://forum.freecodecamp.org/t/need-help-with-my-for-loop-twitch-api-project/177572/2 "2018-03-02T18:19:40Z")

</div>

use `let` instead of `var`  
`let apiNum = i.toString();`

Read this to understand why this works: [https://hacks.mozilla.org/2015/07/es6-in-depth-let-and-const/](https://hacks.mozilla.org/2015/07/es6-in-depth-let-and-const/)

---

<div class="post-metadata">

**Author:** ![MeatyJobo](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@MeatyJobo](https://forum.freecodecamp.org/u/MeatyJobo)\
**Post date:** [March 2, 2018, 6:23pm UTC](https://forum.freecodecamp.org/t/need-help-with-my-for-loop-twitch-api-project/177572/3 "2018-03-02T18:23:58Z")

</div>

Oh wow I was so much closer than I thought I was, thank you Elise, thank you as well for posting info as to why it works. Super helpful 😃 Cannot express enough thanks!

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:25pm UTC](https://forum.freecodecamp.org/t/need-help-with-my-for-loop-twitch-api-project/177572/4 "2021-01-17T20:25:30Z")

</div>

Closed on January 17, 2021, 8:25pm UTC


