Team Stat Project

Hi guys, can someone please tell me why I keep getting Undefined. Much appreciated!

const team = {
_players:[
{firstName: ‘Andy’, lastName: ‘Carder’, age: 37},
{firstName: ‘Brad’,lastName: ‘Smith’, age: 21},
{ firstName: ‘Sam’, lastName: ‘Homes’, age: 25}
],
_games:[
{opponent: ‘Lakers’,teamPoints: 100, opponentPoints: 95},
{opponent: ‘Magic’, teamPoints: 125, opponentPoints: 80},
{opponent: ‘Bulls’, teamPoints: 105, opponentPoints: 104}
],
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);
}
}

team.addPlayer(‘Steph’, ‘Curry’, 28);
team.addPlayer(‘Lisa’, ‘Leslie’, 44);
team.addPlayer(‘Bugs’, ‘Bunny’, 76);

console.log(team.Player);

Use the backing variable (this._players) when adding a player.

1 Like

Hi there,
it still did not work. Keep getting undefined :sob:

Try it with,

team.players
1 Like

I managed to find the problem!! iIt was on the console.log(team.Player); instead of console.log(team.players); missed the s on the end and had the letter p in uppercase.

1 Like