Team Stats please help :)

Hi there,

Can you please help me with my code?

I’m getting this error:

Guess I’m doing something wrong with the push method but I can’t figure out what…
I followed the instructions (I think)
image

Here’s my code:

Hope someone can help me :slight_smile:

this.players is indeed undefined, undefined doesn’t have a push methods, that is for arrays

you could use the getter method instead?

If I’m not mistaken the code should be:

this._players

Referencing the _players array.

or you could use the getter method?

Adding the ‘_’- to this.players in the push method worked! Thank you both! :slight_smile:

Simple mistake but now I understand.

image

And my code: https://gist.github.com/c66792bdef900926bb0d656cc0ef9cc1

Thank you for your help, much appreciated :slight_smile:

Yea, my bad.
This works too:

this.getplayers().push(player);

But now I’m confused, because in the instruction video Colina (hope I’m spelling it correct) doesn’t use ‘_’ on players.push(player). But she created a players property at the beginning. And I thought that this push method referred to that property… But when she adds the push method, she doesn’t use '’, but her code still works!!

So… what do I not understand?

if you named the getter method players, then yes, you can do players.push(), then you are using the getter.

getters are special properties