SchoolCatalogue: "this is not defined

Hello everyone,

I am currently working on the School Catalogue in the Intermediate Javascript level.

When I try to create a new instance for Primary, I received an error from the "super(“primary”): “this is not defined”.

According to this StackOverflow post, the problem come from the parent class, here School. But I don’t see any problem with it! As someone a clue ?

Thank you very much

class School {
constructor(name,level, numberOfStudents) {
this._name = name;
this._level = level;
this._numberOfStudents = numberOfStudents;

}
set numberOfStudents (newNumber) {
if(newNumber === ‘number’) {
this._numberOfStudents = newNumber;
}
else {
return ‘Invalid input: numberOfStudents must be set to a Number.’;
}
}
get name() {
return this._name;
}
get level() {
return this._level;
}
get numberOfStudents() {
return this._numberOfStudents;
}
quickFacts() {
console.log(${this._name} educates ${this._numberOfStudents} at the ${this._level} school level.)
}
static pickaSubstituteTeacher(substituteTeacher) {
let substituteTeachers = [substituteTeacher];
let randomNum = Math.floor(Math.random() * substituteTeachers.length);
return substituteTeachers[randomNum];
}
}

class Primary extends School {
constructor(name, numberOfStudents, pickupPolicy) {
super(name);
super(“primary”);
super(numberOfStudents);

this._pickupPolicy = pickupPolicy;

}

get pickupPolicy() {
return this._pickupPolicy;
}

}

class Middle extends School {
constructor(name, numberOfStudents) {
super(name);
super(“middle”);
super(numberOfStudents);

}
};

class High extends School {
constructor(name, numberOfStudents, sportTeams) {
super(name);
super(“high”);
super(numberOfStudents);
this._sportTeams = ;
}
get sportTeams() {
console.log(this._sportTeams);
}
}

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.’);

Hey @giga0775018501,

You can’t call super() twice when you make a new class, so if you want to add multiple values, you need to do super(value1, value2);.

Also, doing something like super("primary"); won’t work, because "primary" isn’t a property of School. Try to find what you need to do instead.

Hint:

You need to set the level parameter.

1 Like