Team Stats Project: .push

Hello everyone, I am not sure why the .push() method is giving me an error, this also happened on the Meal Maker project. When I tried to print out (task 7) it gave me a type error for the .push() method. Is it a syntax error?

const team = {

_players: [

{

firstName: 'Beyonce',

lastName: 'Knowles', 

age: 39,

},

{

firstName: 'Rihanna',

lastName: 'Fenty',

age: 33,

},

{

firstName: 'Solana',

lastName: 'Rowe',

age: 30,

}

],

_games: [

{

  opponent: 'Redskins',

  teamPoints: 50,

  opponentPoints: 27,

},

{

  opponent: 'Hornets',

  teamPoints: 42,

  opponentPoints: 32,

},

{

  opponent: 'Mavericks',

  teamPoints: 65,

  opponentPoints: 42,

}

],

get player() {

return this._players;

},

get games() {

return this._games;

},

addPlayer(firstName, lastName, age) {

let player = {

  firstName: firstName,

  lastName: lastName,

  age: age

}

this.players.push(player)

},

};

team.addPlayer(‘Steph’, ‘Curry’, 28);

do you have a link to the specific lesson?

Thank you!

Edit:
Analyzed further and you have a typo when calling your getter or on the name of the getter.

You have:

this.players.push(player);

Should be

this.player.push(player);

or fix the naming to your getter from player to players here:

  get player() {
    return this._players;
  },

OH I see what your saying - works now thank you! :pray:t5: :pray:t5:

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.