I get :
this.games.push(game)
^
TypeError: Cannot read property ‘push’ of undefined,
I dont understand what is the problem. I mean game is defined in object literal.
Also the message only comes up, when I try to add new games/meals.
I get :
this.games.push(game)
^
TypeError: Cannot read property ‘push’ of undefined,
I dont understand what is the problem. I mean game is defined in object literal.
Also the message only comes up, when I try to add new games/meals.
const team={_players:[{
firstName: 'Pablo',
lastName: 'Sanchez',
age: 11
},
{
firstName: 'Ollin',
lastName: 'Cruz',
age: 6
},
{
firstName: 'Anahi',
lastName: 'Lukacs',
age: 3
} ],
__games:[
{
opponent: 'Broncos',
teamPoints: 32,
opponentPoints: 27
},
{
opponent: 'Puchi',
teamPoints: 28,
opponentPoints: 20
},
{
opponent: 'Muchi',
teamPoints: 15,
opponentPoints: 20
} ],
get games() {
return this._games},
get players() {
return this._players
},
addPlayer(firstName,lastName,age){
let player ={firstName:firstName,
lastName: lastName,
age: age} ;
this.players.push(player)
},
addGame(opponent,teamPoints, opponentPoints){
let game={opponent: opponent,
teamPoints:teamPoints,
opponentPoints:opponentPoints};
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('Titans', 100, 98);
team.addGame('Mumis', 89, 93);
team.addGame('Bubi', 23, 18);
console.log(team.games)
Thx for the GummiDuck. I just found solution after days of checking code over and over.
so problem resolved?
type error as always
I mean typing