Build a Library Step #18

Can someone help me find what’s wrong with my code? Thanks in advance.

class Media {

  constructor (title) {

    this._title = title;

    this._isCheckedOut = false;

    this._rating = [];

  }

  get title () {

    return this._title;

  }

  get isCheckedOut () {

    return this._isCheckedOut;

  }

  get rating () {

    return this._rating;

  }

  toggleCheckOutStatus () {

    this.isCheckedOut = !this.sCheckedOut;

  }

  getAverageRating () {

    let ratingsSum = this.ratings.reduce((accumulator, rating) => accumulator + rating, 0);

    const ratingLength = rating.length;

    return ratingSum / this.ratings.length();

  }

  set isCheckedOut (value) {

    this._isCheckedOut = value;

  }

  addRating (value) {

    this.ratings.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();

console.log(historyOfEverything.isCheckedOut);

historyOfEverything.addRating(4);

historyOfEverything.addRating(5);

historyOfEverything.addRating(5);

console.log(historyOfEverything.getAverageRating());

I see several spelling discrepancies. ratings for example is not the same as rating. If you run your code, and then read the error messages, they’ll direct you where to look. When something is undefined it doesn’t exist (was never defined).

1 Like

@gguirao13 You do have a few spelling errors as @midlindner pointed out. Also .length does not need (). I was able to fix the spelling errors + the above and your code functions as intended. :slight_smile: So good work!

Thanks for the helpful replies. This coding stuff gets very difficult when you’re severely nearsighted.

Just keep at it! Functionally your code was spot on. You’ll just have to give your code a good look syntactically in the future. :blush: