Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created June 27, 2019 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/fad39f20c7daeb81c1f8f9d3597f194a to your computer and use it in GitHub Desktop.
Save codecademydev/fad39f20c7daeb81c1f8f9d3597f194a to your computer and use it in GitHub Desktop.
Codecademy export
const team = {
_players: [
{firstName: 'Amy',
lastName: 'Smith',
age: 22
},
{firstName: 'Anwar',
lastName: 'Oleg',
age: 40
},
{firstName: 'Connie',
lastName: 'Ng',
age: 110
}
],
_games: [
{opponent: 'Dolphins',
teamPoints: 3,
opponentPoints: 12
},
{opponent: 'Eggheads',
teamPoints: 37,
opponentPoints: 8
},
{opponent: 'Eagles',
teamPoints: 100,
opponentPoints: 10
},
],
};//HINT TO STEP 6 SAYS I CLOSE THE TEAM OBJECT WITH }; SO I DID. WAS THAT WRONG?
addPlayer(firstName, lastName, age) {
let player = {
firstName: firstName,
lastName: lastName,
age: age
};// THE HINT TO STEP 6 SAYS I DON'T PUT T// CLOSING CURLY UNTIL AFTER THE PUSH BELOW...how many curly braces should i have by now? in this above step 6, we added a method TO THE TEAM OBJECT, YET OUTSIDE OF THE BRACES OF THE TEAM OBJECT? And we gave the method 3 parameters, and we defined the method with curly braces, and said to invoke this method we must define player as having 3 properties - the same as the parameters.
this.players.push(player);//this is still part of step 6. It takes the player object of the addPlayer method //note it is singular player unlike players of team object. And it says: let us add the player property to the players array????? is that what it says? Is that what the pushing is doing???
}, // the HINT to step 6 says to put a closed curly brace AND a COMMA, BUT I'M NOT SURE WHY. So, the addPlayer method consists of announcing the method and parameters and defining the method as creating a variable called player, which is in the SINGULAR, unlike the players property of the team object okay..but there is MORE to the addPlayer method..this method requires an action wherein you push, that is -- you add this new variable player to the players property. Is that right? Is that what we are doing? So, this addPlayers method must be defined outside of the team object?
//Now, i'm told BELOW THE TEAM OBJECT, to invoke the addPlayer method on these people. Well, addPlayer is a method to call on the team object. So that is fine. The team has 2 properties: players and games. So, it's fine to call the addPlayer method on the team object. Still not sure why we used the singular term player when we created the object.
team.addPlayer('Steph', 'Curry', 28);
team.addPlayer('Lisa', 'Leslie', 44);
team.addPlayer('Bugs', 'Bunny', 76);
console.log(team.players); // so, now I have an error. Should I have closing braces after this?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment