Classes need help understanding the setter

I tried to continue on the class project but as I put averageTestScores as an array on the Parent Class I wanted to set the setter to give the sum of the average of the array but what I get returned in the console is the array instead. below is the images and the code… on quickFacts() method how that is right below the setters how can I call the setters inside it I tried this. But doesn’t work

class School {
  constructor(name, level, numberOfStudents, averageTestScores, schoolOverview) {
    this._name = name;
    this._level = level;
    this._numberOfStudents = numberOfStudents;
    this._averageTestScores = averageTestScores;
    this._schoolOverview = schoolOverview;
  }
  get averageTestScores() {
    return this._averageTestScores;
  }
  set averageTestScores(scoreArray) {
    this._averageTestScores.push(scoreArray);
    let sumOfArray = this._averageTestScores.reduce((accumulator, nextVal) => accumulator + nextVal);
    let average = sumOfArray / this._averageTestScores.length
    return this._averageTestScores = average;
  }
quickFacts() {
      console.log(`${this.name} educates ${this.numberOfStudents} students at the ${this.level} school level and they had an average score of ${this.averageTestScores} in last year.`)
  }
}
class Primary extends School {
  constructor(name, numberOfStudents, pickupPolicy, averageTestScores) {
    super(name, 'primary', numberOfStudents, averageTestScores);
    this._pickupPolicy = pickupPolicy;
  }
  get pickupPolicy() {
    return this._pickupPolicy;
  }
}
const lorraineHansbury = new Primary('Lorraine Hansbury', "514", 'Students must be picked up by a parent, guardian, or a family member over the age of 13.', [54, 53, 45, 10]);
lorraineHansbury.quickFacts();

this._averageTestScores stores an array. And in the method quickFacts you use the getter to retrieve and log the unchanged array stored in that variable. In the setter you defined the equation which calculates the average, but you never use that setter. Use the code from the setter in your getter instead.

thanks but what is setter for then now I have it as empty?

You could use it to add scores retrospectively to an existing instance for example. But for that purpose you’d have to change it (just delete the code after the line where you push the value).

for instance I want to add to the setter like this

lorraineHansbury.averageTestScores = 20;

then I catch that 20 value and push it to the array from the setter than send this to the getter how would i do this?

I deleted the push value i had the one you told me i get a TypeError now saying reduce is not a function

school-catalog/app.js:20
    let sumOfArray = this._averageTestScores.reduce((accumulator, nextVal) => accumulator + nextVal);
                                             ^

TypeError: this._averageTestScores.reduce is not a function

without having this lorraineHansbury.averageTestScores = 20; it is okay

this is the setter atm

set averageTestScores(scoreArray) {
    return this.averageTestScores.push(scoreArray);
  }

getter atm

get averageTestScores() {
    let sumOfArray = this._averageTestScores.reduce((accumulator, nextVal) => accumulator + nextVal);
    let average = sumOfArray / this._averageTestScores.length
    return this._averageTestScores = average;
  }

Yes, that is what I meant. But did you define the setter before the getter? Then swap getter and setter so that this.averageTestScores is not undefined. Also, you can delete the return. You do not return to a calling method/function from the setter.

You do not need an assignment in the getter. You just want to return your value, so just return average.