Build a library

i had problem in this project to execute the getAverage() method it return this console :
false
[Function: getAverageRating] and this is my code :

class Media {
  constructor(title){
    this._title = title;
    this._isCheckedOut = false
    this._ratings = []
  }
 
  get title(){
    return this._title
  }
  get isCheckedOut() {
    return this._isCheckedOut
  }
  set isChekedOut (newisCheckedOut) {
    return this._isCheckedOut = newisCheckedOut
  }

  get ratings() {
    return this._ratings
  }
  toggleCheckedOutStatus (){
   
     return this._isCheckedOut = !this._isCheckedOut
   
  }
  getAverageRating (){
    let ratingsSum = this._ratings.reduce(( currentSum, rating) =>  currentSum + rating, 0)
    return ratingsSum / this._ratings.length
  }
  addRating(rate) {
    this._ratings.push(rate)
  }
}
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(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)
historyOfEverything.addRating(5)
historyOfEverything.addRating(5)
console.log(historyOfEverything.getAverageRating)

Check this line:

Is getAverageRating a method/function, or is it a property? If it’s a function, how do you call a function?

1 Like

Thank you very much my friend

1 Like