On the project where we must create a class media with subclasses book, movie, cd. I get an error on the addRating method.
Heres my code so far
class Media {
constructors(title){
this._title = title;
this._ratings = [];
this._isCheckedOut = false;
}
get title(){
return this._title;
}
get ratings(){
return this._ratings;
}
get isCheckedOut(){
return this._isCheckedOut;
}
toggleCheckedOutStatus(){
if(this._isCheckedOut === true){
this._isCheckedOut = false;
}else {
this._isCheckedOut = true;
}
}
getAverageRating(){
let ratSum = this._ratings.reduce((currentSum, rating) => currentSum + rating, 0) / this._ratings.length;
return ratSum.toFixed(2);
}
addRating(adding){
this._ratings.push(adding);
}
set isCheckedOut(checked){
this.isCheckedOut = checked;
}
}
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.toggleCheckedOutStatus();
console.log(historyOfEverything.isCheckedOut);
historyOfEverything.addRating([4,5,5]);
console.log(historyOfEverything.getAverageRating());
I get the error TypeError: Cannot read property ‘push’ of undefined
at Book.addRating