Build a Library Project - setter is not a function

Hello,

I started working on the Build a Library project in Classes chapter. I got to writing up the setter and I wanted to test everything before I move forward. I tested my getters, everything seems fine. But when I tried to change isCheckedOut value with a setter I get an error: TypeError: testBook.isCheckedOut is not a function.

Can someone please explain why it’s happening?

Please see my code below. Thank you!

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

  set isCheckedOut(status) {
    this._isCheckedOut = status;
  }
}

const testBook = new Media('Test Book');
console.log(testBook.title);
console.log(testBook.isCheckedOut);
testBook.isCheckedOut(true);

Hi,

With setters you don’t need to invoke it as a function call.
You can just write testBook.isCheckedOut = true;. Note if you remove the setter, this type of line wouldn’t work.

Hope this helps!

Amazing, thank you so much! Big help!