Introduction to javascript / 9 / Build a library : Error : .getAvgRate is not a function


#1

So i’m working on this exercise :
https://www.codecademy.com/courses/introduction-to-javascript/projects/build-a-library?action=resume_content_item

I have an error when i try to use the getAvgRate() function outside of the Media class the console return me this error : TypeError: Media.getAvgRate is not a function witch means thaht this function does not exist.
I can’t find a solution right now so if some one here can help me this would very great.
Here’s my code :

class Media {
  constructor () {
    this._title = '';
    this._isCheckedOut = false;
    this._ratings = [2, 3, 5];
  }
  
  get title() {return this._title}
  get isChekedOut() {return this._isCheckedOut}
  get ratings() {return this._ratings}
  set isChekedOut(a) {this._isCheckedOut = a}
  
  toggleCheckedOutStatus() {
    if (this._isCheckedOut) {
      this.isCheckedOut = false
    }else{
      this.isCheckedOut = true
    };
  }
  getAvgRate() {
    let a = this._ratings.reduce() / this._ratings.length();
    return a;
  }
  addRating(a) {this._ratings.push(a)}
}
console.log(Media.title);
console.log(Media.getAvgRate());

Also here’s the full error if you need it :

Summary
/home/ccuser/workspace/learn-javascript-classes-build-a-library/app.js:27
console.log(Media.getAvgRate());
                                  ^

TypeError: Media.getAvgRate is not a function
    at Object.<anonymous> (/home/ccuser/workspace/learn-javascript-classes-build-a-library/app.js:27:19)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)
    at bootstrap_node.js:542:3

Any advice would be very apreciated :grinning:
Thanks in advace.


#2

The reduce method takes a callback…

ratings.reduce((a, b) => a + b)

#3

Ok thx i’m going to check MDN for more info on .reduce