Build library - Step 25 Create class called Catalog that holds all of the Media items in our library

hi all,
has anyone done this step ?

1 Like

I think I’ve done this in a previous exercise/project! Can I help you with something?

1 Like

hey thanks for the getting in touch
i have just started having ago at it ,atm am am a bit stuck in trying to create a remove method in the catalog object
here is my code:

// Catalog object that holds all of the Media items in library

let catalog = {

  _books: [],

  _movies:[],

  _cds:[],

  get books(){

      return this._books;

  },

  get Movies(){

      return this._movies;

  },

  get cds(){

      return this._cds;

  },

  addBook(book){

    this._books.push(book)

  },

  addMovies(movie){

    this._movies.push(movie)

  },

  addCds(cd){

      this._cds.push(cd)

  },

 remove(){

   

 }

}

catalog.addBook(book1)

catalog.addMovies(movie1)

catalog.addCds(cd1)

catalog.addCds(cd1)

catalog.addCds(cd1)

console.log(catalog.books)

console.log(catalog.Movies)

console.log(catalog.cds)

There is no I in ‘team’, or, ‘we’.

Currently working on this project but I am getting an unexpected token error when I add the getter for director. I’m not quite sure what’s going on here.

class Media {
  constructor(title) {
    this._title = title;
    this._isCheckedOut = false;
    this._ratings = [];
  }

  get title() {
    return this._title;
  }

  get isCheckedOut() {
    return this._isCheckedOut;
  }

  get ratings() {
    return this._ratings;
  }

    set isCheckedOut(value) {
    return this._isCheckedOut = value;
  }

  toggleCheckOutStatus() {
    this._isCheckedOut = !this._isCheckedOut;
  }

  getAverageRating() {
    let ratingSum = this.ratings.reduce((currentSum, rating) => currentSum + rating, 0);
    return ratingSum / this.rating.length;
  }

  addRating(value) {
    this.values.push(value);
  }
}

class Book extends Media {
    
    constructor(author, title, pages) {
      super(title);
      this._author = author;
      this._pages = pages;
    }

    get author() {
      return this._author;
    }

    get pages() {
      return this._pages;
    }    
}

class Movie extends Media {
  
  constructor(director, title, runTime) {
    super(title);
    this._director = director;
    this._runTime = runTime;

    get director() {
      return this._director;
    }

    get runTime() {
      return this._runTime;
    }
  }
}

const historyOfEverything = new Book('Bill Bryson', 'A Short History of Nearly Everything', 544);

historyOfEverything.toggleCheckOutStatus();

The getters should not be inside the constructor. Move a closing brace up to just above them.

Yes that was the issue. Thank you for your help.

1 Like