Hi, when I checked the solution video to compare my work, I noticed that the Setter for numberOfStudents is where they’re checking whether or not the value entered is a number. I’ve tried to do it this way as well but I can’t just get the (function If) inside the mentioned Setter to start.
I’ve tried to set a String just to trigger the warning, but it won’t even run through the (function If) nested in the Setter.
-------------Main Class
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;
};
//This is where I believe the issue is at.
set numberOfStudents(value){
if(typeof value !== 'number'){
console.log('it is NOT a number')
}else{
this._numberOfStudents = value;
}
};
quickFacts(){
console.log(`${this.name} educates ${this.numberOfStudents} students at the ${this.level} school level.`)
};
static pickSubstituteTeacher(substituteTeachers){
let random = Math.floor(Math.random()*((substituteTeachers.length)-0));
return substituteTeachers[random];
};
};
//Sub class Primary
class Primary extends School{
constructor(name, numberOfStudents, pickupPolicy ){
super(name, 'Primary', numberOfStudents);
this._pickupPolicy = pickupPolicy;
}
get pickupPolicy(){
return this._level;
};
};
//Instance creation
//(Notice I’m sending a letter ‘a’ hoping it would trigger the number warning but it just sets it as an attribute)
const lorraineHansbury = new Primary('Lorraine Hansbury','a','Students must be picked up by a parent, guardian, or a family member over the age of 13.',4);
lorraineHansbury.quickFacts();
console.log(lorraineHansbury);
console.log(School.pickSubstituteTeacher(['Nataly','Andres','Kaoru']));