Team Stats Project

Hello! For some reason I can t log in my code below, it keeps accusing code error in line 6. I already checked commas and compared with walkthrough video and other projects. Help please.

const team = {
_players: [{firstName: “Pablo”, lastName: “Sanches”, age: 11},
{firstName: “Carlo”, lastName: “Rodriguez”, age: 12},
{firstName: “Naio”, lastName: “Gonzalez”, age: 13} ],
_games: [
{opponent: “Bronco”, teamPoints: 42, opponentPoints: 27},
{opponent: “Santos”, teamPoints: 40, opponentPoints: 25},
{opponent: “Vasco”, teamPoints: 38, opponentPoints: 23} ],

get players() {return this._players;},
get games() {return this._games;},

addPlayer(firstName, lastName, age) {
const player = {
firstName: firstName,
lastName: lastName,
age: age,
};
this._players.push(player);
},
};

team.addPlayer(Steph, Curry, 28);
team.addPlayer(Lisa, Leslie, 44);
team.addPlayer(Bug, CurryBunny, 76);

console.log(team.players);

You’ll want to share an exact copy whenever you share code because others will use what you posted to reproduce what you describe, and what you posted won’t do that because it’s different.

I’d go as far as to say that your issue is likely to be related to exactly that treatment of “details”!

Something you can do yourself without sharing any code though, is to isolate that line, see if it raises that error by itself, and if so inspect it closer, or otherwise include more from what was above.

2 Likes

What have we learned about getters?

Did you find any other errors?

Roy, I have been studying codes for 2 and a half months, I believe the “Team Stats” Project can be too overwhelming for beginers. I am not sure what you mean by you kind reply…

The errors are obvious and will raise a syntax error that will reveal the problem. There is a detail regarding getters that needs to be understood.

In the addPlayer method, change this line,

this._players.push(player);

to this, (after you fix the syntax errors)

this.players = player;

It will reveal something that you may have overlooked.

At the bottom of your code,

console.log(team.players);
2 Likes

If I get to make suggestions on how to continue from here:

  1. If you fixed it, great. Done.
  2. If not, narrow it down as much as possible yourself. You might find the problem yourself by doing that, and whatever code you share should be the minimal amount required for your question anyway.
  3. Can’t do anything more yourself? Post your code. Make sure that it is an exact copy. That means you should not be able to see any difference at all, and you should be able to copy it back from your post into your editor and still getting the same outcome when running it, it should not have changed at all, not a single character in the code should be different. It’s like taking your cat to the veterinary without bringing the cat. Don’t bring the dog either. The cat. That cat, not another cat, no matter how similar.
2 Likes

Got it! I totally forgot to put quotations ("") on all string values below ‘_games’. I believe the code is finally ready, and it is working. Thanks again!

const team = {
_players: [{firstName: “Pablo”, lastName: “Sanches”, age: 11},
{firstName: “Carlo”, lastName: “Rodriguez”, age: 12},
{firstName: “Naio”, lastName: “Gonzalez”, age: 13} ],
_games: [
{opponent: “Bronco”, teamPoints: 42, opponentPoints: 27},
{opponent: “Santos”, teamPoints: 40, opponentPoints: 25},
{opponent: “Vasco”, teamPoints: 38, opponentPoints: 23} ],

get players() {return this._players;},
get games() {return this._games;},

addPlayer(firstName, lastName, age) {
const player = {
firstName: firstName,
lastName: lastName,
age: age
};
this._players.push(player);
},

addGame(opponent, teamPoints, opponentPoints) {
const game = {
opponent: opponent,
teamPoints: teamPoints,
opponentPoints: opponentPoints
};
this._games.push(game);
},
};

team.addPlayer(“Steph”, “Curry”, 28);
team.addPlayer(“Lisa”, “Leslie”, 44);
team.addPlayer(“Bug”, “CurryBunny”, 76);
team.addGame(“Madrid”, 45, 25);
team.addGame(“Barcelona”, 41, 26);
team.addGame(“StGemain”, 43, 27);

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

1 Like