Help with school catalogue


#1

Hi, when I Call the quickFacts, I get the return but without the values of the constructors. Where do I make a mistake?

This is my code:

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;
}
  
  quickFacts(name,numberOfStudents, level){
    console.log(`${name} educates ${numberOfStudents} students, typically between the ages of ${level}.`)
  }
  
  static pickSubstituteTeacher(substituteTeachers){

   let randomTeacher = Math.floor(Math.random() * substituteTeachers.length);
    return substituteTeachers[randomTeacher];
  }
  
set numberOfStudents(newNumberOfStudents){
  if (typeof newNumberOfStudents === number){
    this._numberOfStudents = newNumberOfStudents;
  }
    else {
      console.log('Invalid input: numberOfStudents must be set to a Number.');
    }
}
};

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

class HighSchool extends School{
  constructor(name, level, numberOfStudents){
    super(name, numberOfStudents)
    this._sportsTeams = [''];
  }
  
  get sportsTeams(){
    return this._sportsTeams;
    console.log(this._sportsTeams);
  }
}

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

lorraineHansbury.quickFacts();

console.log(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);

#3

look at the following two lines:

quickFacts(name,numberOfStudents, level)
lorraineHansbury.quickFacts();

find them in your program, one is the method definition/declaration and the other the method call.

When declaring the method, you give it 3 parameters. But then you call the method, and you provide no arguments for the parameters. So all the parameters are undefined

but the whole point of the constructor is that we can access the name, level and numberOfStudents properties through self, so that we don’t have to provide the arguments twice (DRY, very important in programming)