Nalini1998 / Project_Public

MIT License
2 stars 0 forks source link

Team Stats Project #555

Closed Nalini1998 closed 1 year ago

Nalini1998 commented 1 year ago

We want to create, retrieve, and add information about our favorite sports team. Basketball, soccer, tennis, or water polo, we pick it ourselves. It’s our job to create data using the JavaScript data structures at our disposal: arrays and objects.

After we create these data structures in this project, feel free to challenge ourselves to gain insights from them. For example, we might want to get the total number of games our team has played, or the average score of all of their games.

Nalini1998 commented 1 year ago
// Completed by @Meow.Nalini98

const team = {
  _players : [
    {firstName: 'Pete', lastName: 'Wheeler', age: 54},
    {firstName: 'Nalini', lastName: 'Vo', age: 25},
    {firstName: 'Austin', lastName: 'Trang', age: 28}
  ],
  _games : [
    {opponent: 'Soccer', teamPoints: 10, opponentPoints: 4},
    {opponent: 'Tennis', teamPoints: 17, opponentPoints: 5},
    {opponent: 'Voleyball', teamPoints: 20, opponentPoints: 8}
  ],

  get players() {
    return this._players;
  },

  get games() {
    return this._games;
  },

  addPlayer(newFirstName, newLastName, newAge) {
    let player = {
      firstName: newFirstName,
      lastName: newLastName,
      age: newAge
    };
    this.players.push(player);
  },

  addGame(newOpponent, newTeamPoints, newOpponentPoints) {
    let game = {
      opponent: newOpponent,
      teamPoints: newTeamPoints,
      opponentPoints: newOpponentPoints
    };
    this.games.push(game);
  }
};

team.addPlayer('Bugs', 'Bunny', 76);
team.addGame('Titans', '100', 98);
console.log(team.players);
console.log(team.games);