Build a Library task error

Project link CLICK

class Media {
  contructor(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(paramOne) {
    this._isCheckedOut = paramOne;
  }
  toggleCheckOutStatus() {
    this._isCheckedOut = !this._isCheckedOut
  }
  getAverageRating() {
   let ratingsSum = this.ratings.reduce((currentSum, rating) => currentSum + rating);
    return ratingsSum / this.ratings.length
  }
  addRating(paramOne) {
    this.ratings.push(paramOne);
  }
}

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()
console.log(historyOfEverything.isCheckedOut)
historyOfEverything.addRating(1)
historyOfEverything.addRating(1)
historyOfEverything.addRating(5)
console.log(historyOfEverything.getAverageRating())

Result: TypeError: Cannot read property ‘push’ of undefined

.addRating method isn’t working. Seems like I don’t see this little detail that interrupts

Slight typo here, should work when fixed, I overlooked it myself a couple of times while looking for the culprit. :slight_smile:

1 Like

Ha ha… Thank you. I was checking everything except first lines of code. I thought it’s obvious, “how can I make mistake there? :grin:

1 Like