Hello Codecademy Community,
I’m almost done with my Build a Library project, however, when I added in parameters for ratings to ensure the inputs are between 1 and 5, I broke my code. The error I’m receiving is for ‘class Book extends Media’ and it’s apparently a ‘SyntaxError: Unexpected identifier’.
I have a feeling the class Media extension code broke as my addRating() method has a problem. Can anyone help?
Thank you
Rohini
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(newIsCheckedOut) {
this._isCheckedOut = newisCheckedOut;
}
toggleCheckOutStatus() {
this._isCheckedOut = !this._isCheckedOut;
}
getAverageRating() {
let ratingsSum = this._ratings.reduce((currentSum, rating) => currentSum + rating, 0);
let lengthOfRatings = this._ratings.length;
return ratingsSum / lengthOfRatings;
}
addRating(rating) {
if (rating < 1 || rating > 5){
console.log('Error! Please rate between 1 and 5')} else {
this._ratings.push(rating);
}
}
class Book extends Media {
constructor(title, author, pages) {
super(title);
this._author = author;
this._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);
historyOfEverything.addRating(4);
historyOfEverything.addRating(5);
historyOfEverything.addRating(5);
console.log(historyOfEverything.getAverageRating());
const speed = new Movie('Speed', 'Jan De Bont', 116);
speed.toggleCheckOutStatus();
console.log(speed.isCheckedOut);
speed.addRating(1);
speed.addRating(1);
speed.addRating(5);
console.log(speed.getAverageRating());
//console.log(speed._title);
//console.log(speed._director);