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