Hi, I’m hoping someone can clarify my code. I’ve just finished everything from the School Catalogue project, and it works! Where I’m confused is if I comment out my last console.log statement, all of my results are undefined:
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(newNumberOfStudent){
if(newNumberOfStudents === number){
this._numberOfStudents = newNumberOfStudents;
} 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 pickSubstituteTeacher(substituteTeachers){
let substituteTeacherIndex = Math.floor(Math.random() * substituteTeachers.length -1)
return substituteTeachers[substituteTeacherIndex]
}
};
class PrimarySchool extends School{
constructor(name, numberOfStudents, pickupPolicy){
super (name);
this._level = 'primary';
this._numberOfStudents = 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;
console.log(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.')
console.log(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)
Could someone please explain how my last console.log statement (alSmith.sportsTeams) “allows” my previous, “console.log(School.pickSubstituteTeacher([‘Jamal Crawford’, ‘Lou Williams’, ‘J. R. Smith’, ‘James Harden’, ‘Jason Terry’, ‘Manu Ginobli’]));” to produce a result? I’m confused as to why, when I comment out console.log(alSmith.sportsTeams), all other logs are undefined with the exception of “console.log(lorraineHansbury.quickFacts());”
How does one log impact the other?
Thanks!