-
Notifications
You must be signed in to change notification settings - Fork 0
/
Team Stats.js
51 lines (46 loc) · 1.36 KB
/
Team Stats.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//create team object
const team = {
//populate array with three players
_players: [
{firstName: "Pablo", lastName: 'Sanchez', age: 11},
{firstName: 'Isaac', lastName: 'Tait', age: 35},
{firstName: 'Tadashi', lastName: 'Tait', age: 2}
],
//populate array with three games
_games: [
{opponent: 'Broncos', teamPoints: 42, opponentPoints: 27},
{opponent: 'Red Sox', teamPoints: 12, opponentPoints: 2},
{opponent: 'Giants', teamPoints: 13, opponentPoints: 7}
],
//create getter methods for _players & _games. There is no need to create setter methods becaus the values do not need to change
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(opp, myPts, oppPts) {
const game = {
opponent: opp,
teamPoints: myPts,
opponentPoints: oppPts
};
this._games.push(game);
},
};
team.addPlayer('Steph', 'Curry', 28);
team.addPlayer('Lisa', 'Leslie', 44);
team.addPlayer('Bugs', 'Bunny', 76);
console.log(team.players);
team.addGame('Angels', 8, 12);
team.addGame('Saints', 34, 12);
team.addGame('Ducks', 9, 12);
console.log(team.games);