Team stats project

so Im doing the team stats project and my code keeps missing off the first 2 players and the first 2 games when i print to console can someone explain why. Here is my code:

const team = {

  _players: [

    {

    firstName: 'Owen',

    lastName: 'Farrel',

    age: 32,

    

   firstName: 'Jonny',

    lastName: 'May',

    age: 30,

    

   firstName: 'Tom',

    lastName: 'Curry',

    age: 25

    },

  ],

  _games: [

    {

      opponent: 'France',

      teamPoints: 24,

      opponentPoints: 20,

     opponent: 'Italy',

      teamPoints: 42,

      opponentPoints: 14,

      opponent: 'Wales',

      teamPoints: 18,

      opponentPoints: 21, 

  },

  ],

    get players(){

      return this._players;

    },

    get games(){

       return this._games;

  },

  addPlayer(firstName, lastName, age){

    let player = {

      firstName: firstName,

      lastName: lastName,

      age: age

    };

    this.players.push(player);

  },

  addGame(oppName, teamPnts, oppPnts){

    let game = {

      opponent: oppName,

      teamPoints: teamPnts,

      opponentPoints: oppPnts

    };

    this.games.push(game);

  },

  };

  team.addPlayer('Steph', 'Curry', 28);

  team.addPlayer('Lisa', 'Leslie', 44);

  team.addPlayer('Bugs', 'Bunny', 76);

  team.addGame('South Africa', 17, 24);

  team.addGame('New Zealand', 32, 18);

  team.addGame('Japan', 28, 7);

console.log(team.players);

console.log(team.games);

If your code has been copied right, your players array only has 1 object, where you in effect overwrite the same three properties.

You want more like this:

_players: [
  {
    firstName: 'Owen',
    lastName: 'Farrel',
    age: 32,
  // Close the first object
  }, 
 {
    firstName: ‘Jonny’,
    lastName: 'May',
    age: 30,
  },
  {
    firstName: ‘Tom’,
    lastName: 'Curry',
    age: 25
  },
],

Also look at _games

1 Like

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