Build a Library Classes Project

Hey all! I’m working on the classes project - Build a Library and I can’t seem to get the .toggleCheckOutStatus method to work. It is initially set to false and it does not change. Can someone please take a look at my code and let me know if they find the error? thanks you!

Learn JavaScript Syntax: Classes | Codecademy

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

  get title() {
    return this._title;
  }

  get artist() {
    return this._artist;
  }

   get isCheckedOut() {
     return this._isCheckedOut;
   }

   set isCheckedOut(value) {
     this._ischeckedOut = value;
   }

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

  getAverageRating() {
    let ratingSum = this._ratings.reduce((prevValue, currValue) => prevValue + currValue, 0)
    return ratingSum / this._ratings.length;
  }

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

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

  get author() {
    return this._author;
  }

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

class Movie extends Media {
  constructor(title, director, runTime) {
    super(title);
    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);

historyOfEverything.toggleCheckOutStatus();
console.log(historyOfEverything.isCheckedOut);

There is one fly in the ointment. May be more, but fix this one first and see what happens.

The lower case ‘c’ !! so easy to miss! thank you for helping me swat that fly.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.