Help with Build a Library project

Hello other JavaScript learners and programmers!

I’m having trouble with the Build a Library project, part of the Classes topic in the Learn JavaScript tree.

Here is my Code thus far:

class Media {
  constructor (title){
    this._title = title;
    this._ratings = [];
    this._isCheckedOut = false;
  get title (){
    return this.title;
  get isCheckedOut (){
    return this._isCheckedOut;
  get ratings (){
    return this._ratings;
  set isCheckedOut(isCheckedOut){
    return this._isCheckedOut
    this._isCheckedOut = !this._isCheckedOut
  getAverageRating() {
    let ratingsSum = 
  this.ratings.reduce((accumulator, currentValue) => {
      return accumulator + currentValue;
  //not sure about the syntax for both getAverageRating and addRating because it I dont know if it is calculating an average from the unset array ??
class Book extends Media {
  constructor(author, title, pages){
    this._author = author;
    this._pages = pages;
  get author (){
    return this._author;
  get pages (){
    return this._pages;
class Movie extends Media {
  constructor(director, title, runTime){
      this._director = director;
      this._runTime = runTime;
  get director (){
    return this._director;
  get runTime (){
    return this._runTime;
const historyOfEverything = new Book("Bill Bryton", "A Short History of Nearly Everything", 544)


historyOfEverything.addRating(4, 5, 5);

I think my problem is with the syntax of the getAverageRating method, or the addRating method, because it returns ‘undefined’ to the console - I’m struggling to understand where I’ve gone wrong !

Any advice would be massively appreciated, thank you in advance, C :upside_down_face:

Hi Callum,
the reason why you get ‘undefined’ is that you don’t return the reduced value from the method. You assign it to a variable instead.
If you would return the calculated sum it would not be the average value of all ratings, but the sum of it, so you have to slightly adjust what’s being returned from the reduce method.
After you added the ratings by calling the ‘addRating’ method, you should log the _ratings array. I guess the output is not what you expect it to be.

please don’t post this in a solved topic if the problem you observe is not related to this solution.
I recommend that you create a new topic – please format your post as described in this guide: That makes your code more readable to others.