Help with JavaScript Object project (Team Stats, Task 8)

Hello,

I have been stuck on this for quite some time now, and I can’t really figure out where I am wrong.
The link to the project is: https://www.codecademy.com/paths/front-end-engineer-career-path/tracks/fecp-javascript-syntax-part-ii/modules/fecp-learn-javascript-syntax-objects/projects/team-stats

Here is the code:

addGame (opponent, teamPoints, opponentPoint) {
    let game = {
      opponent: oppenent,
      taemPoints: teamPoints,
      oppenentPoints: opppenentPoints
    },
     this.games.push(game);
  }

Here is the error message:

/home/ccuser/workspace/learn-javascript-objects-team-stats/app.js:59
     this.games.push(game);
     ^^^^
SyntaxError: Unexpected token this
    at createScript (vm.js:53:10)
    at Object.runInThisContext (vm.js:95:10)
    at Module._compile (module.js:543:28)
    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)

Lots of spelling errors. Review your labels.

As for the unexpected ‘this’, it points to a possibility of the object having been closed before this method. Check your blocking and braces.

Thanks looks like I forgot to close the player object in the method as well, but now I am getting a different error.

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

/home/ccuser/workspace/learn-javascript-objects-team-stats/app.js:26
      this.players.push(player);
                  ^

TypeError: Cannot read property 'push' of undefined
    at Object.addPlayer (/home/ccuser/workspace/learn-javascript-objects-team-stats/app.js:26:19)
    at Object.<anonymous> (/home/ccuser/workspace/learn-javascript-objects-team-stats/app.js:39:6)
    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)

Again, check your blocking. this is the team object, if I recall. Your method needs to be inside that enclosure. Be sure your getter is properly scoped, as well.

get players () {
  return this._players;
}
1 Like