School catalogue

First thing that comes up is,


should be,


Okay, I see now that averageTestScores is an attribute with a getter. Is this one that I earlier said needed to invoked? Belay that, thanks.

return this._averageTestScores.reduce((a, b) => {a + b}) / this._averageTestScores.length;

The above method is read-only so can use the getter rather than direct access. Rule of getters… If there is one, use it every time to access the property’s value.

return this.averageTestScores.reduce((a, b) => {a + b}) / this.averageTestScores.length;

Great thanks for usefull remarks. However, i’m sorry, any success, completely lost in just three words. Evidently, it is a luck of systematic knowledge. Logically everythings is clear, practically unable to apply it.

What errors are being raised? Does the code function without console errors?

there are lots of (in the new ver):

You have an error in the console which is giving a pretty good indication - you’re calling averageTestScores without first having passed any test scores in it:

line 67: lorraineHan.averageTestScores();

At this stage the array is empty. Push some values into it first.

Then you will find that your averageTestScores function doesn’t work. Remove the curly braces from around a+b in its code. This function would be better as a getter, btw.

I have your code returning results. You’re nearly there.

Given that each extended class has an attribute,

this._averageTestScores = []

We can give them methods, such as,

  get averageTestScores () {
    return this._averageTestScores;
  addTestScore (score) {
  classAverage () { 
    return this.averageTestScores.reduce((a, b) => a + b) / this.averageTestScores.length

There will be no averageTestScores parameter in the constructor. We will need to load them in individually…


Now when we poll the scores and report the average,


We get,

[ 90, 85, 75, 90 ]

Hey there, thanks a lot!

1 Like

You’re welcome. There is still work to be done if you ever wish to come back to the project (or continue on, now).

For instance, exam scores to form a database from which to calculate exam class average, term class average, or student averages (an extra feature).

Above, how might we allow a list of scores in one go, rather than one at a time?

Can the attributes and methods be inherited from the parent class? Answer, yes, so there would be one distribution of the codebase. Individual subclasses can override if need be.

So now the School class will carry the load. We add in a property that I called meanTestScores (to lose three letters from the name).

The multiple entries problem I solved by having two methods, rather than a bunch of logic in one.

  get meanTestScores () {
    return this._meanTestScores;
  addTestScore (score) {
  addTestScores (scores) {
  classAverage () { 
    return this.meanTestScores.reduce((a, b) => a + b) / this.meanTestScores.length

Lots ways this project can go.

1 Like

Hi, I apperciate your feedback, it is especially usefull and motivating for me at the moment.

As you probably noticed, I’ve stuck over an elementary things. That’s because I am distracted doing this exercise along with going through learning process of theory materials of this course. It’s important for me at the moment to create a solid base knowledge as far as it possible for beginner to aproach tasks more or less adequately, as well as mixing it up with practice.

I like your idea to go further in this regards, to extend evaluation of tests scores and to improve code in such way, forthermore, initially i had some thoughts of extending this exercise in this way.

I’ll be back in short time, after absorbing portion of general theory , with some proposal of mentioned above code development :slight_smile: .

1 Like

sorry sorry i guess i had not mastered the format thing in the forum…sorry!

may i know why not using statics here?

ok cool, so why level doesn’t need to be included?

No need to apologize ;). Just a little advice for a future post.

Hi, can you have a look at this issue pls.


Does anyone have the full code solution? My syntax is off but I can’t find where for the life of me.

also, can someone explain this issue?

"Maximum call stack size exceeded at PrimarySchool.get name [as name] "


Hello @laurafitzpatrick123.

This error indicates an infinite loop or circular reference. I don’t think you’ll have any luck getting the “full code solution” on the forum. There are many of us who are glad to help, if you’ll post your code, but giving out solutions to exercises is a no, no. If you would like help, and choose to post your code, please click the </> button in the menu bar first. Then paste your code in the space indicated. It will preserve your formatting, and make it possible for us to copy and run your code ourselves to help you work through the issues.

Please can someone help me understand how to create a SchoolCatalog that holds the collection of schools under the extra work at step 19 so you can display all the different schools under one class?

I just can’t figure it out. I don’t know if the info is stored within the class itself or if it can only be accessed via the instances? Would it require a new method within the SchoolCatalog that would grab the info from the other classes?

When creating a new SchoolCatalog instance do you directly reference the classes themselves or just the other instances you created?

I feel there is a simple solution but it’s completely evading me, I’m absolutely stumped. TIA.


I’m curious as to why this project instructed us to generate the random number to be one less than the substituteTeachers array, and also what is the purpose of the console.log in the sportsTeam getter?

Thanks for any help.

If you had the following array of persons:

> const subs = ["Mr. Smith", "Mrs. Smith", "Mr. Brown", "Mrs. Brown"]

What’s the length of the array?

> console.log(subs.length)

What is the index of the last element?

> console.log(subs.indexOf("Mrs. Brown"))

If we didn’t specify that the random number to be used as the index for selecting a random substitute teacher had to be in the range of 0 to 3 (the maximum possible is one less than the length of the array) we could end up with an index of 4. If we try to select subs[4] what do we get?

> console.log(subs[4])

While the students might enjoy having undefined for a substitute teacher, I don’t think the school administrators or the parents would approve. :wink:

The purpose of console.log() is always the same. Print something to the console. This project allows you some freedoms. You click off the steps as you complete them. When I did this one, I did not use console.log() in the getter. It seemed inconsistent to me, so I returned a string that contained the sports teams. In the end it doesn’t really matter that much if the getter prints the teams, or returns a string for the caller to print (ie. console.log(someSchool.sportsTeams)).