# Debugging Help on Basketball Stat App

**URL:** <https://forum.code.org/t/debugging-help-on-basketball-stat-app/34448>\
**Category:** Coding and Debugging Help\
**Created:** [March 24, 2021, 4:21pm UTC](https://forum.code.org/t/debugging-help-on-basketball-stat-app/34448 "2021-03-24T16:21:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mindyw](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@mindyw](https://forum.code.org/u/mindyw)\
**Post date:** [March 24, 2021, 4:21pm UTC](https://forum.code.org/t/debugging-help-on-basketball-stat-app/34448/1 "2021-03-24T16:21:13Z")

</div>

I have a student working on his own app (not for AP) that could use some help debugging the ‘undefined’ error code.  
\*\*Link to the project or level:\*\*[Code.org - App Lab](https://studio.code.org/projects/applab/kSq9nnC34e-oRlQKJ-GLs28-f5BiFtMTpyzduCuX2Yg)  
\*\*What I expect to happen:\*\*He is trying to push one of the player buttons to add a rebound for the player. The list is where the rebound count should start.  
**What actually happens:** It doesn’t count the rebounds using the index. Errors and says ‘players is undefined’.  
**What I’ve tried:** He tried to remove the purple players from the events and changed up the ‘addRebounds’ function.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/d/df8b21cd4b246b6466313bedf84b6494f771a391.png)

---

<div class="post-metadata">

**Author:** ![IMPixel](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/impixel/32/6744_2.png) [@IMPixel](https://forum.code.org/u/IMPixel)\
**Post date:** [March 24, 2021, 8:51pm UTC](https://forum.code.org/t/debugging-help-on-basketball-stat-app/34448/2 "2021-03-24T20:51:22Z")

</div>

I mean, I don’t see why it would be working. Your student is settings an array to a number, not an array, so the next time you press a button, the program tries to run `addRebounds()`, it just fails to do it, as `players` became an integer the last time `addRebounds` was run. If it’s hard to understand, here’s a version with what exactly the program does when a button is pressed. Oh, also another problem is that your student sets players to a number himself on multiple lines.

`addRebounds` is run.  
Console:  
Ok, run addRebounds.  
The player variable turns into a number 1 time (12) after that, it turns into NaN 4 times, as you can’t get the i element of a number.

I hope that explains why it isn’t working, however I’ll now show how to fix this 🙂  
First of all, remove these: ![image](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/2/2bbd7c8ef91838c19e3e447c3adf9f04f4af0c20.png)  
Second of all, in the addRebounds function, don’t set the whole array (players) to a number, set one element of it only.(in other words, turn this ![image](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/9/9e4233abc347f312769811f2c5fc08f876eb52f5.png) to this ![image](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/7/7f9802045939ec4bcada46294078928d9d442b52.png) )

That seems to be it to set the players array to the right thing, however you can’t set an App Lab element’s text to an array. That’s why when you will try to run the code, the text won’t change, it will put out this warning instead:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/a/ac6b245abd100586f2e9d79e4448dd7c88a9ad87.png)

To fix this, I just used the .join javascript array method and it gave me what I wanted.  
Here’s the full code if you need it:

> **[Code.org](https://studio.code.org/users/sign_in)**
>
> Anyone can learn computer science. Make games, apps and art with code.

---

<div class="post-metadata">

**Author:** ![mindyw](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@mindyw](https://forum.code.org/u/mindyw)\
**Post date:** [March 25, 2021, 3:45pm UTC](https://forum.code.org/t/debugging-help-on-basketball-stat-app/34448/3 "2021-03-25T15:45:34Z")

</div>

Thank you so much for the feedback. I am very new to this and struggle to keep up with it all. Your link to the new code just takes me to my dashboard. Any chance you can re-send it? Thank you so much again!

---

<div class="post-metadata">

**Author:** ![IMPixel](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/impixel/32/6744_2.png) [@IMPixel](https://forum.code.org/u/IMPixel)\
**Post date:** [March 25, 2021, 4:27pm UTC](https://forum.code.org/t/debugging-help-on-basketball-stat-app/34448/6 "2021-03-25T16:27:34Z")

</div>

Oh god… I messed up a bit, I don’t know how…  
Anyway, here’s the link to the code: [Code.org - App Lab](https://studio.code.org/projects/applab/ttdLWMZg1r8X9rU-aMSd0KN3OfczWAxsTM993NHF1PU/)

---

<div class="post-metadata">

**Author:** ![IMPixel](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/impixel/32/6744_2.png) [@IMPixel](https://forum.code.org/u/IMPixel)\
**Post date:** [March 25, 2021, 4:28pm UTC](https://forum.code.org/t/debugging-help-on-basketball-stat-app/34448/7 "2021-03-25T16:28:50Z")

</div>

I understood that I had to do that, but after a few minutes of thinking, I realized your student probably wants only one player’s score to go up. In that case he has to assign an event to every single one of the buttons.
