My Team Stats Project - Thoughts?

Hey guys,

I’m new to the forum and to Codecademy in general.

I’d like to hear your feedback about my Team Stat projects code. I’ve read few related topic and haven’t seen anyone approching the getters the way I’ve done, and I’d like to know if you think it’s a good practice or not?

The main difference I’ve noticed in using the For looping methods is that I can obtain a tidier result on the Output? (see different outputs below)

I’d really appreciate any comments or thoughts on this.

Thanks

Team Stat Exercise
]

My Code below:

const team = { _players : [ {firstName: 'Joe',lastName: 'Scholes',age: 31}, {firstName: 'Roberto', lastName: 'Baggio', age: 40 }, {firstName: 'Michael',lastName: 'Owen',age: 27} ], _games : [ {opponent: 'Lakers', teamPoints: 23, opponentPoints:19}, {opponent: 'Bulls', teamPoints: 35, opponentPoints:40}, {opponent: 'Miami', teamPoints: 48, opponentPoints:15} ], get players () { if (this._players){ for (let playersList in team._players ){ console.log (`${team._players[playersList].firstName} ${team._players[playersList].lastName}, ${team._players[playersList].age}`); } } }, get games (){ if (this._games){ for(let gamesList in team._games){ console.log(`${team._games[gamesList].opponent}, ${team._games[gamesList].teamPoints},${team._games[gamesList].opponentPoints}`); } } }, addplayer (newFirstName, newLastName,newAge) { let player = { firstName: newFirstName, lastName: newLastName, age: newAge } this._players.push(player); }, addGame (newOpponent,newTeamPoints, newOpponentPoints) { let game = { opponent: newOpponent, teamPoints: newTeamPoints, opponentPoints: newOpponentPoints, } this._games.push(game); } } team.addplayer('Mike','Lewis','37' ); team.addGame ('Real Madrid', 65,47 ); team.players; team.games;

Output with my code:

Joe Scholes, 31 Roberto Baggio, 40 Michael Owen, 27 Mike Lewis, 37 Lakers, 23,19 Bulls, 35,40 Miami, 48,15 Real Madrid, 65,47

Output when using just a “return” inside the Getter method:

{ firstName: 'Joe', lastName: 'Scholes', age: 31 }, { firstName: 'Roberto', lastName: 'Baggio', age: 40 }, { firstName: 'Michael', lastName: 'Owen', age: 27 }, { firstName: 'Mike', lastName: 'Lewis', age: '37' } ] [ { opponent: 'Lakers', teamPoints: 23, opponentPoints: 19 }, { opponent: 'Bulls', teamPoints: 35, opponentPoints: 40 }, { opponent: 'Miami', teamPoints: 48, opponentPoints: 15 }, { opponent: 'Real Madrid', teamPoints: 65, opponentPoints: 47 }