School Catalog Setter Method

Hello everyone!

I have gone through the school catalog project and everything seems to be working okay except when I test the setter method on my high school instance and pass in a string instead of an integer. What am I missing?

Here is the link

and the code pasted below

class School {
constructor(name, level, numberOfStudents){
this._name = name;
this._level = level;
this._numberOfStudents = numberOfStudents;
get name() {
return this._name;
get level(){
return this._level;
get numberOfStudents() {
return this._numberOfStudents;
console.log(${this._name} educates ${this._numberOfStudents} students at the ${this._level} school level.);
static pickSubstituteTeacher(substituteTeahers){
const randTeach = Math.floor(Math.random() * substituteTeahers.length);
set numberOfStudents(number){
if(typeof number !== ‘number’) {
console.log(‘Invalid input: numberOfStudents must be set to a number’);
} else {
return this._numberOfStudents = number;
class PrimarySchool extends School {
constructor(name, numberOfStudents, pickupPolicy){
super(name, ‘Primary’, numberOfStudents)
this._pickupPolicy = pickupPolicy;

class MiddleSchool extends School {
constructor(name, level, numberOfStudents) {
super(name, ‘Middle’, numberOfStudents)

class HighSchool extends School {
constructor(name, numberOfStudents, sportsTeams){
super(name, ‘High’, numberOfStudents)
this._sportsTeams = sportsTeams;
get sportsTeams() {
return this._sportsTeams;

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


// School.pickSubstituteTeacher([‘Jamal Crawford’, ‘Lou Williams’, ‘J. R. Smith’, ‘James Harden’, ‘Jason Terry’, ‘Manu Ginobli’]);

const alSmith = new HighSchool(‘Al E. Smith’, ‘two-hundred’, [‘Baseball’, ‘Basketball’, ‘Volleyball’, ‘Track and Field’]);


Your setter isn’t used when you create a new instance of HighSchool. You are passing the value for numberOfStudents to the parent class constructor method, so your setter can’t test the value. You could, if you want, not send numberOfStudents to the parent constructor by leaving it out of the super() statement. Then add this line below your super(): this.numberOfStudents = numberOfStudents; this will invoke the setter. Hope this helps!

Thank you! It’s always nice to have set of fresh eyes to look at code.

1 Like