Having an issue that I can’t seem to debug with this project.
Whenever I try to call the pickSubstituteTeacher, I get an error stating that it is not a function.
If I remove static from the initial definition, it works, but I haven’t followed the project instructions. Format appears to match documentation, but obviously, I’ve missed something, or the program would work.
Also. I don’t understand why the bottom line is returning the number of items in the array along with the array.
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(students) {
if(students === Number) {
this._numberOfStudents = students;
} else {
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) {
let myIndex = Math.floor(Math.random() * substituteTeachers.length - 1);
return substituteTeachers[myIndex];
}
}
class Primary extends School {
constructor(name, level, numberOfStudents) {
super(name, level, numberOfStudents, pickSubstituteTeacher);
this._pickUpPolicy = '';
}
get pickupPolicy() {
return this._pickUpPolicy;
}
set pickupPolicy(policy) {
this._pickUpPolicy = policy;
}
}
class Middle extends School {
constructor(name, level, numberOfStudents) {
super(name, 'middle', numberOfStudents, pickSubstituteTeacher);
}
}
class High extends School {
constructor(name, level, numberOfStudents) {
super(name, 'high', numberOfStudents);
this._sportsTeams = [''];
}
get sportsTeams() {
return this._sportsTeams;
}
set sportsTeams(team) {
this._sportsTeams.push(team);
}
}
const lorraineHansbury = new Primary('Lorraine Hansbury', 'primary', 514);
lorraineHansbury.pickupPolicy = '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 High('Al E. Smith', 'high', 415);
alSmith.sportsTeams = ['Baseball', 'Basketball', 'Volleyball', 'Track and Field'];
alSmith.sportsTeams.forEach(team => console.log(`Team: ${team}`));
thanks in advance.