I spent hours figuring out what happened but cannot find it.Please some body help me


#1

const team = {
_players: [
{ firstName: “Pablo”,
lastName: “Sanchez”,
age: 21
},
{
firstName: “Cristiano”,
lastName: “Ronaldo”,
age: 33
},
{
firstName: “Lionel”,
lastName: “Messi”,
age: 31
}
],
_games: [
{
opponent: “Real Madrid”,
teamPoints: 42,
opponentPoints: 14
},
{
opponent: “AC Milan”,
teamPoints: 45,
opponentPoints: 23
},
{
opponent: “Napoli”,
teamPoints: 49,
opponentPoints: 38
}
],

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(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);

team.addGame(“Manchester United”, 43, 32);
team.addGame(“Chelsea”, 43, 54);
team.addGame(“Barcelona”, 54, 32);

console.log(team.players);
console.log(team.games);


#2

Don’t know what’s happening, don’t know how to reproduce.
Please explain:

  • What’s happening differently from what you expect
  • How/where you’re running the code

There are also a lot of syntax errors, is that an exact copy of the code? Easier to reproduce if the code doesn’t have to be fixed first.

lianbawireact.js:3
{       firstName: “Pablo”,
                   ^

SyntaxError: Invalid or unexpected token

#3

Really appreciate it, but I finally figured out luckily that I didn’t know I was using ‘_’ at both of the getter _games and get _players. Thank you so much and Bye.