Build a library - title is not defined error

HI all,

Currently working my way through the build a library project, managed to code up to a point myself, until an error came up.

Having then watched the unstuck dev work through it my code seems correct but the error is still showing.

please help.

class Media {
constructor(Media) {
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(value) {
this._isCheckedOut = value;
}

toggleCheckOutStatus() {
this.isCheckedOut = !this.isCheckedOut;
}

getAverageRating() {
let ratingSum = this.ratings.reduce((sum, rating) => sum + rating, 0);
return ratingSum / this.ratings.length;
}

addRating(value) {
this.ratings.push(value);
}

}
//// end of parent class

//// start of first child
class Book extends Media {
constructor(author, title, pages){
super(title);
this._author = author;
this._pages = pages;
}
get pages() {
return this._pages;
}

get author() {
return this._author;
}
};

//// end of first child

///start of second child

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 historyOfEverything = new Book(‘Bill Bryson’, ‘A Short History of Nearly Everything’, 544);

//historyOfEverything.toggleCheckOutStatus()
//console.log(historyOfEverything.isCheckedOut)

Error Is title is not defined

this._title = title;
^

ReferenceError: title is not defined

However I have added title with the a short history of nearly everything?

Thank you.

Hi @data7412699309
have a look at the constructor of your class Media. Check where you pass the title of the book.

hi @mirja_t

…and breathe… thank you for that, I was stuck for a long time and even now I can’t believe looked over a simple thing.

Thanks again.

2 Likes

You’re welcome. I guess we all know these face palm moments when coding. :slightly_smiling_face:

2 Likes