Team Stats step 7 help

Hi everyone, I have a question with Step 7 of the Team Stats project:

Blockquote Below your team object, invoke your addPlayer method on the following players: Steph Curry Age 28 , Lisa Leslie Age 44 , and Bugs Bunny Age 76 .
Print out the team ‘s players to check they were all properly added.

I have managed to get the new players to print on my console, however, in the process it removes my #1 and # 2 player information that i’ve added and only allows the last player to show up (for a total of 4 players to the console as opposed to 6). I am not sure why this is happening or if this is supposed to happen but any help would be greatly appreciated.

My code is below:

const team = {
  _players: [
    {
      firstName: 'Dan',
      lastName: 'the Man',
      age: 25,
      firstName: 'Billy',
      lastName: 'Bob',
      age: 26,
      firstName: 'Joe',
      lastName: 'Doe',
      age: 23
    }
  ],
  _games: [
    {
      opponent: 'SDSU',
      teamPoints: 7,
      opponentPoints: 27,
      opponent: 'USD',
      teamPoints: 20,
      opponentPoints: 15,
      opponent: 'UCLA',
      teamPoints: 5,
      opponentPoints: 90
    }
  ],

  get_players() {
    return this._players;
  },

  get_games() {
    return this._games;
  },

  addPlayer(firstName, lastName, age) {
    let player = {
      firstName,
      lastName,
      age
    };
    this._players.push(player);
  },
};

team.addPlayer('Steph', 'Curry', 28);
team.addPlayer('Lisa', 'Leslie', 44);
team.addPlayer('Bugs', 'Bunny', 76);

console.log(team._players);

Hello, @fdromero.

The _players property has an array assigned as its value. The array is made up of ‘player’ objects. Each player should be a separate object. Currently, in your team object the players array initially contains only one object:

You have the same issue in the array assigned to the _games property. Each individual object should be surrounded by { }'s. An array of objects would have a structure like this: [{obj1}, {obj2}, {obj3}], or more specific to this project:

_arrayOfObjects: [
  {
    prop1: 'val1',
    prop2: 'val2',
    prop3: 'val3'
  },
  {
    prop1: 'val1',
    prop2: 'val2',
    prop3: 'val3'
  },
  {
    prop1: 'val1',
    prop2: 'val2',
    prop3: 'val3'
  }
],

Hi @midlindner,

Thank you for your thoughtful response! This makes sense and fixed my problem. Now on to finish the rest of this assignment! :slight_smile:

1 Like

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