School Catalogue

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;
}
set numberOfStudents(value){
if(value.isNaN()){
  console.log('Invalid input: number of students must be set to a number')
} else {
  this._numberOfStudents = value;
}
}
  quickFacts(){
    console.log('${this._name} educates ${this._numberOfStudents} students at the ${this._level} school level.');
  }
  static pickSubstituteTeacher(substituteTeachers){
    substituteTeachers=[];
    let aRandomNumber = Math.floor(Math.random() * substituteTeachers.length);
    return substituteTeachers[aRandomNumber];
  }
}

class PrimarySchool extends School {
  constructor(name, numberOfStudents, pickupPolicy){
    super(name, 'primary', numberOfStudents)
    this._pickupPolicy = pickupPolicy;
  }
  get pickupPolicy(){
    return this._pickupPolicy;
  }
}

class MiddleSchool extends School {
  constructor(name, 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 tollgate = new PrimarySchool('Tollgate', '88', 'On time');

console.log(tollgate);

const testSchool = new HighSchool('Test school', 899, 'Blue Jays');
console.log(testSchool);

can anyone explain why this does not throw the error “Invalid input: number of students must be set to a number”?

If you place a console.log() inside the setter, you will see that the setter isn’t used anywhere. As such, no validation takes place. Where do you setter is being called/used?