JavaScript Team Stat Project Return TypeError

const team = { _player: [ { firstName: "Sachin", lastName: "Tendulkar", age: 45 }, { firstName: "Mahendra", lastName: "Dhoni", age: 40 }, { firstName: "Virat", lastName: "Kohli", age: 33 } ], _games: [ { opponent: "England", teamPoints: 45, opponentPoints: 60 }, { opponent: "Pakistan", teamPoints: 40, opponentPoints: 70 }, { opponent: "South Africa", teamPoints: 60, opponentPoints: 61 } ], get players() { return this._players; }, get games() { return this._games; }, addPlayer(newFirstName, newLastName, newAge) { let player = { firstName: newFirstName, lastName: newLastName, age: newAge }; this.players.push(player); } }; team.addPlayer("Bugs", "Bunny", 76); console.log(team.players);
1 Like

You have a typo on line 2.

// Your code:
_player: [

// It should be:
_players: [
1 Like

typo on line 28.

this._players.push

Because of the presence of the getter

get players() {
    return this._players;
  }

line 28 i.e. this.players.push(player) won’t cause an error.

I changed the players typo and then modified to _player, and the code worked.