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