JavaScript_Team Stats
10635 ワード
const team = {
_players: [{
firstName: 'Marco',
lastName: 'Rossi',
age: 28},
{firstName: 'Ian',
lastName: 'Williams',
age: 34},
{firstName: 'Jamie',
lastName: 'Bowden',
age: 21},
],
_games: [{
opponent: 'Dragon',
teamPoints: 2,
opponentPoints: 3},
{opponent: 'Tiger',
teamPoints: 6,
opponentPoints: 4},
{opponent: 'Zeus',
teamPoints: 0,
opponentPoints: 1},
],
get players() {
return this._players;
},
get games() {
return this._games;
},
addPlayer(firstName, lastName, age) {
let newPlayer = {
firstName,
lastName,
age,
};
this._players.push(newPlayer);
},
addGame(opponent, teamPoints, opponentPoints) {
let newGame = {
opponent,
teamPoints,
opponentPoints,
};
this._games.push(newGame);
}
};
team.addPlayer('Steph', 'Curry', 28);
team.addPlayer('Lisa', 'Leslie', 44);
team.addPlayer('Bugs', 'Bunny', 76);
team.addGame('Titans', 4, 1);
team.addGame('Hurricane', 0, 0);
team.addGame('Killer', 1, 7);
console.log(team.players);
console.log(team.games);
/* output:
{ firstName: 'Marco', lastName: 'Rossi', age: 28 },
{ firstName: 'Ian', lastName: 'Williams', age: 34 },
{ firstName: 'Jamie', lastName: 'Bowden', age: 21 },
{ firstName: 'Steph', lastName: 'Curry', age: 28 },
{ firstName: 'Lisa', lastName: 'Leslie', age: 44 },
{ firstName: 'Bugs', lastName: 'Bunny', age: 76 }
{ opponent: 'Dragon', teamPoints: 2, opponentPoints: 3 },
{ opponent: 'Tiger', teamPoints: 6, opponentPoints: 4 },
{ opponent: 'Zeus', teamPoints: 0, opponentPoints: 1 },
{ opponent: 'Titans', teamPoints: 4, opponentPoints: 1 },
{ opponent: 'Hurricane', teamPoints: 0, opponentPoints: 0 },
{ opponent: 'Killer', teamPoints: 1, opponentPoints: 7 }
*/
Reference
この問題について(JavaScript_Team Stats), 我々は、より多くの情報をここで見つけました https://velog.io/@sebely/JavaScriptTeam-Statsテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol