Incorrectly defined property in one of my classes? Intermediate JS Course

Hey all, I’m currently on Step 16 of the Build a Library project in Intermediate JS. I am attempting to call my toggleCheckoutStatus() method on a new variable I created but I’m getting an error relating to not having isCheckedOut defined in my parent class. I’ve gone over it around 6 times searching for a simple spelling error however I’m sure I’ve not made one. If anyone could point me in the right direction to where the error is/why my code is incorrect that would be great :slight_smile:.

The error is pointing me to line 24, which is my isCheckedOut method.

Here is the full code:

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;
  }

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

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

  getAverageRating() {
    let ratingsSum = this.ratings.reduce(
      (currentSum, rating) => currentSum + rating,
      0
    );

    return ratingsSum / this.ratings.length;
  }

  set isCheckedOut(value) {
    this._isCheckedOut = 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 = number;
  }

  get director() {
    return this._director;
  }

  get number() {
    return this._number;
  }
}

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

historyOfEverything.toggleCheckOutStatus();

In the code below, you are not actually changing the value in your if statement. In the if statement you are returning the result of the conditional statement and not changing the value of _isCheckedOut You also appear to be mixing accessing the instance variable of _isCheckedOut and internally using the setter isCheckedOut();

I suggest the following changes to get what I believe is your desired behavior:

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

I see, thank you for clearing that up for me. :smiley: