Team Stats project: addPlayer and addGame method without declaring "player" and "game" variable

Hello community,
in the Game Stats excercises, I’ve created the addPlayer and addGame as follows:

const team = {
  _players: [
    {firstName: 'Roger', lastName: 'Bishop', age: 23},
    {firstName: 'Turi', lastName: 'Passalacqua', age: 25},
    {firstName: 'Mauro', lastName: 'De Mauro', Age: 27}
  ],
  _games: [
    {opponent:'Modica', teamPoints: 70, opponentPoints: 65},
    {opponent:'Scicli', teamPoints: 62, opponentPoints: 73},
    {opponent:'Vittoria', teamPoints: 72, opponentPoints: 64}
  ],
  get players() {
    return this._players;
  },
  get games() {
    return this._games;
  },
  addPlayer(newFirstName, newLastName, newAge) {
     this._players.push({firstName: newFirstName, lastName: newLastName, age: newAge});
  },
  addGame(newOpponent, newTeamPoints, newOpponentPoints) {
    this._games.push({opponent: newOpponent, teamPoints: newTeamPoints, opponentPoints: newOpponentPoints});
  }
};

Which works fine for me, as players and games are correctly added to the array when I call the methods.

By looking at the video walkthrough, I see the developer is using a slightly different solution, where he’s declaring 2 variables called “player” and “game” inside each method:

I was wondering if my solution is still correct and, if this is the case, why the developer added the “player” and “game” variables.

Hope question is clear.
Thank you

There is no harm in explicitness, and often what we consider explicit enough is also enough to escape the reader at a quick glance. The example in the screenshot is likely the preferred way to write it, given it spells everything out. Yes, your solution is going to work as expected, but it does make it harder to read and debug. Something to keep in mind.

1 Like

OK, thank you for the answer.

1 Like