School Catalogue

Can someone explain what I have done wrong?

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(newNumberOfStudents) {
if (typeof numberOfStudents === ‘number’) {
return this.numberOfStudents;
} else {
console.log(‘Invalid input:’ + this.numberOfStudents + ’ must be set to a Number.')
}
}

quickFacts() {
console.log(${this.name} educates ${this.numberOfStudents} students at the ${this.level} school level.)
}

static pickSubstituteTeachers(substituteTeachers) {
const randInt = Math.floor(Math.random() * substituteTeachers.length);
return substituteTeacher[randInt];
}
}

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, 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 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);

I am getting this error.

Lorraine Hansbury educates 514 students at the primary school level.
/home/ccuser/workspace/learn-javascript-classes-school-catalog/app.js:60
School.pickSubstituteTeacher([‘Jamal Crawford’, ‘Lou Williams’, ‘J. R. Smith’, ‘James Harden’, ‘Jason Terry’, ‘Manu Ginobli’]);
^

TypeError: School.pickSubstituteTeacher is not a function
at Object. (/home/ccuser/workspace/learn-javascript-classes-school-catalog/app.js:60:8)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3

1 Like

Hi, you function’s name is pickSubstituteTeachers but you are calling pickSubstituteTeacher.

1 Like

Thank you, it’s not the first time when I make mistakes like this.