School Catalogue

Hi all,

I need some help understanding the super() method in the School Catalogue challenge project.

So, my code for the Primary School child class looks like this:

class PrimarySchool extends School {
  constructor(name, level, numberOfStudents, pickUpPolicy) {
    super(name, 'primary', numberOfStudents);
    this._pickUpPolicy = pickUpPolicy;    

  get pickUpPolicy() {
    return this._pickUpPolicy;

In terms of creating an instance of that class, the exercise asks us to pass 3 arguments (i.e name, numberOfStudents, pickUpPolicy) but I don’t quite understand why this is the case since there are 4 parameters in the constructor method. Of course, when I tried passing 3 arguments (instead of 4), the console threw an error. To get around this, I did the following:

const lorraineHansbury = new PrimarySchool('Lorraine Hansbury', undefined, 514, 'Students must be picked up by a parent, guardian, or a family member over the age of 13.');

Is there a better way to create an instance of the PrimarySchool class? Using “undefined” as one of the arguments doesn’t seem very elegant to me.

Any advice is appreciated!


The constructor only needs to have parameters for the arguments you pass in during invocation. So for example, the fact that it’s primary (by class name) means that you don’t need to invoke

const school_one = new PrimarySchool("ps 51", "primary", 500, "no policy");

but rather something like this

const school_one = new PrimarySchool("ps 51", 500, "no policy");

I know you mentioned you tried this and it gave you an error, but that’s an issue of how the constructor is being used. So the PrimarySchool constructor should reflect this.

(I’m assuming the School constructor take is name, level, numberOfStudents.)

I’ll give you a concrete example from the previous exercise… omitting the methods (I arbitrarily modified the CD functionality so that it would do something similar to what you’re trying to do). You can see that it can call the methods of the parent class no with no problem:

class Media{
        this._title = title; 
        this._isCheckedOut = false;
        this._ratings = [];

class CD extends Media{
    constructor(artist, songs){
        super("Every CD is Blackbird");
        this._artist = artist;
        this._songs = songs;

const test3 = new CD("santana", []);

//prints "Every CD is Blackbird"
console.log(test3.isCheckedOut); //parent method works
//prints true
//prints "santana"

Thank you for your explanation! I really appreciate it.

I initially went with what you’ve done too but I was a bit unsure as to whether doing this matched the brief (maybe I misunderstood the brief). In the “hint”, it asked us to directly pass “primary” as an argument in the super method, which to be honest, threw me off a bit because I wasn’t told this was possible in the preceding lessons. Nonetheless, I did it but it ended up causing problems when it came to creating an instance of that object.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.