School catalogue

#21

First thing that comes up is,

newNumberOfStudents.isNaN()

should be,

isNaN(newNumberOfStudents)

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;
Use of isNan() in the School Catalogue Project
#22

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.

#23

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

#24

there are lots of (in the new ver):

#25

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.

#26

Given that each extended class has an attribute,

this._averageTestScores = []

We can give them methods, such as,

  get averageTestScores () {
    return this._averageTestScores;
  }
  addTestScore (score) {
    this._averageTestScores.push(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…

lorraineHansbury.addTestScore(90);
lorraineHansbury.addTestScore(85);
lorraineHansbury.addTestScore(75);
lorraineHansbury.addTestScore(90);

Now when we poll the scores and report the average,

console.log(lorraineHansbury.averageTestScores);
console.log(lorraineHansbury.classAverage());

We get,

[ 90, 85, 75, 90 ]
85
1 Like
#27

Hey there, thanks a lot!

1 Like
#28

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) {
    this._meanTestScores.push(score)
  }
  addTestScores (scores) {
    this._meanTestScores.push(...scores)
  }
  classAverage () { 
    return this.meanTestScores.reduce((a, b) => a + b) / this.meanTestScores.length
  }

Lots ways this project can go.

1 Like
#29

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
#30

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

#31

may i know why not using statics here?

#32

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

#33

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

#34

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

Thanks.