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


So i’m working on this exercise :

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
      this.isCheckedOut = true
  getAvgRate() {
    let a = this._ratings.reduce() / this._ratings.length();
    return a;
  addRating(a) {this._ratings.push(a)}

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


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.


The reduce method takes a callback…

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


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