code:
const team = {
_players: [{
firstName: ‘amin’,
lastName: ‘Harit’,
age: 25,
},
{
firstName: ‘Solomon’,
lastName: ‘Okoronkwo’,
age: 30,
},
{
firstName: ‘Genaro Ivan’,
lastName: ‘Gattuso’,
age: 38,
},
],
_games: [{
opponent: ‘Bochum’,
teamPoints: 5,
opponentPoints: 0
},
{
opponent: ‘BXB’,
teamPoints: 4,
opponentPoints: 2
},
{
opponent: ‘Bayern’,
teamPoints: 3,
opponentPoints: 0
}],
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(opponentName, teamsPoints, opponentsPoints) {
let game = {
opponentName: opponentName,
teamsPoints: teamsPoints,
opponentsPoints: opponentsPoints,
}
this.game.push(game);
},
};
team.addPlayer(‘Steph’, ‘Curry’, 28);
team.addPlayer(‘Lisa’, ‘Leslie’, 44);
team.addPlayer(‘Bugs’, ‘Bunny’, 28);
team.addGame(‘köln’, 5, 3);
team.addGame(‘wolfsburg’, 2, 0);
team.addGame(‘gladbach’, 3, 1);
error:
/home/ccuser/workspace/learn-javascript-objects-team-stats/app.js:45
this.players.push(player);
^
TypeError: Cannot read property ‘push’ of undefined
at Object.addPlayer (/home/ccuser/workspace/learn-javascript-objects-team-stats/app.js:45:17)
at Object. (/home/ccuser/workspace/learn-javascript-objects-team-stats/app.js:57:8)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)