Hello! here is my solution to the team-stats project, let me know what you think on how I can code this better. I had trouble with the previous object oriented project, meal-maker, but after completing this one, Objects, getters, and setters make a bit more sense.
const team = {
_players:[
{
firstName: 'Pablo',
lastName: 'Sanchez',
age: 11
},
{
firstName: 'Pete',
lastName: 'Maravich',
age:13
},
{
firstName: 'Tim',
lastName: 'Duncan',
age: 12
}
],
_games:[
{
opponet: 'Warriors',
teamPoints: 72,
opponetPoints: 71
},
{
opponet: 'Kings',
teamPoints: 69,
opponetPoints: 84
},
{
opponet: 'Raptors',
teamPoints: 94,
opponetPoints: 86
}
],
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(opponet, teamPoints, opponetPoints) {
let game = {
opponet: opponet,
teamPoints: teamPoints,
opponetPoints: opponetPoints
}
return this.games.push(game);
},
};
team.addPlayer('Steph', 'Curry', 28);
team.addPlayer('Lisa','Leslie', 44);
team.addPlayer('Bugs','Bunny', 76);
console.log(team.players);
team.addGame('Heat', 95, 80);
team.addGame('Hornets', 99, 96);
team.addGame('Nets', 91, 87);
console.log(team.games);
Giving feedback for the first time? AWESOME! Check out this video for a boost of confidence: How to Review Someone Else’s Code
Feel free to remove this message before posting.
Cheers!
—Codecademy Community Managers