Team Stats


#1

https://www.codecademy.com/courses/learn-javascript-objects/projects/team-stats?course_redirect=introduction-to-javascript

When I use “return this._players.join(” “);” I got an error. But works “return this._players”

const team = {
  _players: [
    {firstName: "Lebron",
    lastName: "James",
     age: 33 },
    {firstName: "Michael",
    lastName: "Jordan",
     age: 49},
    {firstName: "Kobe",
    lastName: "Bryant",
     age: 41}
  ],
  _games: [
    {opponent: "Heat", 
            teamPoints: 142, 
            opponentPoints: 127},
           {opponent: "Raptors",
            teamPoints: 102, 
            opponentPoints: 87},
           {opponent: "Indiana", 
            teamPoints: 99, 
            opponentPoints: 86}
          ],
  '''get players() {
  return this._players.join(" ");
  },''' //not working
  get games() {
   return this._games;
  },
  addPlayer(firstName, LastName, age) {
    let player = {
      firstName: "Alex",
      lastName: "Freak",
      age: 19
    };
    this.players.push(player);                            //shows me an error when use .join(" ")
  },
  addGame(opponent, teamPoints, opponentPoints) {
    let score1 = {
      opponent: "Golden State",
      teamPoints: 66,
      opponentPoints: 55
    };
    this.games.push(score1);
    
  }
  };
 
team.addPlayer("Steph", "Curry", 28);
team.addPlayer("Lisa", "Leslie", 44);
team.addPlayer("Bugs", "Bunny", 76);
team.addGame("NY", 99, 65);
team.addGame("GS", 98, 66);
team.addGame("LA", 125, 69);

 console.log(team.players);

#2

the getter is being called when you want to read/get the value of the property, so for example here:

this.players.push(player);   

but .join() returns a string, and a string doesn’t have a push method


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.