Advertisement
makispaiktis

Codecademy - 23rd Exercise (Team Stats - JS)

Dec 24th, 2019 (edited)
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let team = {
  2.   // Array of objects-players
  3.   _players: [{firstName: 'Thomas', lastName: 'Boufikos', age: 20},
  4.             {firstName: 'Diego', lastName: 'Maradona', age: 50},
  5.             {firstName: 'Cristiano', lastName: 'Ronaldo', age: 35}],
  6.  
  7.   _games: [{opponent: 'Bayern', teamPoints: 60, opponentPoints: 50},
  8.           {opponent: 'Chelsea', teamPoints: 80, opponentPoints: 40},
  9.           {opponent: 'Real Madrid', teamPoints: 45, opponentPoints: 25},
  10.           ],
  11.  
  12.   get players(){
  13.     return this._players;
  14.   },
  15.   get games(){
  16.     return this._games;
  17.   },
  18.  
  19.   addPlayer(firstName, lastName, age){
  20.     let player = {
  21.       firstName,
  22.       lastName,
  23.       age
  24.     };
  25.     this.players.push(player);
  26.   },
  27.  
  28.   addGame(opponent, teamPoints, opponentPoints){
  29.     let game = {
  30.       opponent,
  31.       teamPoints,
  32.       opponentPoints
  33.     };
  34.     this.games.push(game);
  35.   }
  36. };
  37.  
  38. // MAIN FUNCTION
  39. team.addPlayer('Steph', 'Curry', 28);
  40. team.addPlayer('Lisa', 'Leslie', 44);
  41. team.addPlayer('Bugs', 'Bunny', 76);
  42. console.log(team.players);
  43. console.log();
  44. team.addGame('Olympiacos', 80, 70);
  45. team.addGame('Juventus', 60, 55);
  46. team.addGame('Tottenham', 50, 60);
  47. console.log(team.games);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement