Hey!
I finished the Team Stats project (https://www.codecademy.com/courses/introduction-to-javascript/projects/team-stats), however I’d like to add the average score of the team and also the total number of games it has played.
Honestly don’t know how to start, objects got me confused…
This is my code so far:
const team = {
_players: [
{firstName: ‘Bob’,
lastName: ‘Smith’,
age: 20},
{firstName: ‘John’,
lastName: ‘Williams’,
age: 33},
{firstName: ‘Dave’,
lastName: ‘Brown’,
age: 28}
],
_games: [
{opponent: ‘Arsenal’,
teamPoints: 30,
opponentPoints: 42},
{opponent: ‘Chealsea’,
teamPoints: 27,
opponentPoints: 35},
{opponent: ‘Juventus’,
teamPoints: 30,
opponentPoints: 28}
],
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’, 50, 40);
team.addGame(‘Liverpool’, 50, 100);
team.addGame(‘Real Madrid’, 50, 15);
console.log(team._players);
console.log(team._games);