Classes - Build library stuck

On the project where we must create a class media with subclasses book, movie, cd. I get an error on the addRating method.

Heres my code so far

class Media {
    this._title = title;
    this._ratings = [];
    this._isCheckedOut = false;

  get title(){
    return this._title;

  get ratings(){
    return this._ratings;

  get isCheckedOut(){
    return this._isCheckedOut;

    if(this._isCheckedOut === true){
      this._isCheckedOut = false;
    }else {
      this._isCheckedOut = true;

    let ratSum = this._ratings.reduce((currentSum, rating) => currentSum + rating, 0) / this._ratings.length;

    return ratSum.toFixed(2);



  set isCheckedOut(checked){
    this.isCheckedOut = checked;

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

  get author(){
    return this._author;

  get pages(){
    return this._pages;

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

  get director(){
    return this._director;

  get runTime(){
    return this._runTime;

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

I get the error TypeError: Cannot read property ‘push’ of undefined
at Book.addRating

Hello, @blogpro21075, and welcome to the forums.

Could you post your entire code? Be sure to format it properly using the preformatted text button </>. See this post for more details on formatting code.

updated with entire code

1 Like

Well, if you add in a console.log() to inspect the value in question, you’ll find something interesting:

Try it, and compare the output to what you would expect.


Notice anything missing from the output?

this: Book { _author: ‘Bill Bryson’, _pages: 544, _isCheckedOut: true }

Where are _title and _ratings?
Why would they be missing?
Where is the code that is supposed to add those properties?
Is anything amiss there?

Thanks! I didn’t know we needed to list title and ratings in the extended constructor since it was already in the super.

You don’t. Look closely at the constructor for your Media class:


The properties in this constructor were not added due to the misspelling. :wink: