I’m stuck on step 18 of the Build A Library Project, where I have to add 3 numbers to the ratings array of my new instance of a book sub class. The “addRatings” method belongs to the parent class, but I am supposedly supposed to have access to it since my book inherits that method. However, what is happening is that I’m getting an “undefined” error that doesn’t make any sense. It’s as if the “Book” child class isn’t properly inheriting the methods, getters, and setters, from the parent, “Media”. My code is below. What am I doing wrong?
URL for exercise: https://www.codecademy.com/courses/learn-intermediate-javascript/projects/build-a-library
class Media {
constuctor(title) {
this._title = title;
this._isCheckedOut = false;
this._ratings = [1,4,5];
}
get title() {
return this._title;
}
get isCheckedOut() {
return this._isCheckedOut;
}
get ratings() {
return this._ratings;
}
set isCheckedOut(newCheckStatus) {
this._isCheckedOut = newCheckStatus;
}
toggleCheckStatus() {
this.isCheckedOut = !this.isCheckedOut;
}
getAverageRating() {
let sumRatings = this.ratings.reduce(
(currentSum, rating) => currentSum + rating,
0
);
return sumRatings / this.ratings.length;
}
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 newBook = new Book(
"Bill Bryson",
"A short History of Nearly Everything",
544
);
newBook.toggleCheckStatus();
console.log(newBook.isCheckedOut);
console.log(newBook._ratings)
newBook.addRating(4);
newBook.addRating(5);
newBook.addRating(5);