Errror when creating an instance of HighSchool

Hey Guys,

This is the link to the School Catalogue Project: https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-22-javascript-syntax-part-iii/modules/wdcp-22-learn-javascript-syntax-classes/projects/school-catalog

The problem I am facing is with the Class HighSchool, here is the code for the class:


class HighSchool extends School{
  constructor(name, numberOfSudents, sportsTeams){
    super(name, 'High School', numberOfStudents);
    this._sportsTeams = sportsTeams;
  }

  get sportsTeams(){
    return this._sportsTeams;
  }
}

When creating an instance of HighSchool as below, I receive the following error (screenshot)

const alSmith = new HighSchool('Al E. Smith', 415, ['Baseball', 'Basketball', 'Volleyball', 'Track and Field']);

I can’t seem to figure out where this error is coming from, as the HighSchool class is exactly the same as the PrimarySchool class, and I am not getting any error when creating an instance of that.

Here is the full code of the project:

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

  get schoolName(){
    return this._name;
  }

  get schoolLevel(){
    return this._level; 
  }

  get numberOfStudents(){
    return this._numberOfStudents;
  }

  set numberOfStudents(newNumberOfStudents){
    if((typeof newNumberOfStudents) != number){
      console.log('Invalid input: numberOfStudents must be set to a Number.');
    } 
  }

  quickFacts(){
    console.log(this._name + ' educates ' + this._numberOfStudents + ' students at the ' + this._level + ' school level.' );
  }

  static pickSubstituteTeacher(substituteTeachers){
    console.log(substituteTeachers[(Math.floor(Math.random)*(substituteTeachers.length))]);
  }
}

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

  get pickupPolicy(){
    return this._pickupPolicy;
  }
}

class HighSchool extends School{
  constructor(name, numberOfSudents, sportsTeams){
    super(name, 'High School', 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.');

lorraineHansbury.quickFacts();
School.pickSubstituteTeacher(['Jamal Crawford', 'Lou Williams', 'J. R. Smith', 'James Harden', 'Jason Terry', 'Manu Ginobli']);

const alSmith = new HighSchool('Al E. Smith', 415, ['Baseball', 'Basketball', 'Volleyball', 'Track and Field']);

console.log(alSmith.sportsTeams);

Read the error message closely. ReferenceError: numberOfStudents is not defined. So, where was it supposed to be defined? It is a parameter of the constructor function, correct? Or is it? :wink:

1 Like