School Catalogue

HI! Can someone check my code to validate if it is correct? Please i want to understand what is missing…

class School { constructor(name,numberOfStudents,level) { this._name = name; this._numberOfStudents = numberOfStudents; this._level = level; } get name() { return this._name; } get numberOfStudents() { return this._numberOfStudents; } get level() { return this._level; } quickFacts() { console.log(`${this._name} educates ${this._numberOfStudents} students at the ${this._level} school level.`) } static pickSubstituteTeacher(substituteTeachers) { let num = Math.floor(substituteTeachers.length * Math.random()); console.log(substituteTeachers[num]); } 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,'primary'); this._pickupPolicy = pickupPolicy; } get pickupPolicy() { return this._pickupPolicy; } } class HighSchool extends School { constructor(name,numberOfStudents,sportsTeams) { super(name,numberOfStudents,'high'); this._sportsTeams = sportsTeams; } get sportsTeams() { console.log(this._sportsTeams); } } const lorraineHansbury = new PrimarySchool('Lorraine Hansbury',25,'Students must be picked up by a parent, guardian, or a family member over the age of 13.') lorraineHansbury.quickFacts(); School.pickSubstituteTeacher(['Joan','Ben','John','Marvin']); const alSmith = new HighSchool('Al E. Smith',415,['Baseball', 'Basketball', 'Volleyball', 'Track and Field']) console.log(alSmith._sportsTeams); // undefined

class School {
constructor(name,numberOfStudents,level) {
this._name = name;
this._numberOfStudents = numberOfStudents;
this._level = level;
}

get name() {
return this._name;
}
get numberOfStudents() {
return this._numberOfStudents;
}
get level() {
return this._level;
}
quickFacts() {
console.log(${this._name} educates ${this._numberOfStudents} students at the ${this._level} school level.)
}
static pickSubstituteTeacher(substituteTeachers) {
let num = Math.floor(substituteTeachers.length * Math.random());
console.log(substituteTeachers[num]);
}
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,‘primary’);
this._pickupPolicy = pickupPolicy;
}
get pickupPolicy() {
return this._pickupPolicy;
}
}

class HighSchool extends School {
constructor(name,numberOfStudents,sportsTeams) {
super(name,numberOfStudents,‘high’);
this._sportsTeams = sportsTeams;
}
get sportsTeams() {
console.log(this._sportsTeams);
}
}

const lorraineHansbury = new PrimarySchool(‘Lorraine Hansbury’,25,‘Students must be picked up by a parent, guardian, or a family member over the age of 13.’)
lorraineHansbury.quickFacts();

const alSmith = new HighSchool(‘Al E. Smith’,415,[‘Baseball’, ‘Basketball’, ‘Volleyball’, ‘Track and Field’])
console.log(HighSchool._sportsTeams);

School.pickSubstituteTeacher([‘Joan’,‘Ben’,‘John’,‘Marvin’]);

Hello web4629010938,

The error in your code is on the line console.log(alSmith._sportsTeams);. You are trying to access the _sportsTeams property directly, but it is a private property (by convention, due to the underscore at the beginning of the name).

The correct way to access the sports teams is through the getter method sportsTeams that you defined in the HighSchool class. So, instead of console.log(alSmith._sportsTeams);, you should use alSmith.sportsTeams; to invoke the getter and obtain the sports teams.

class School { constructor(name, numberOfStudents, level) { this._name = name; this._numberOfStudents = numberOfStudents; this._level = level; } get name() { return this._name; } get numberOfStudents() { return this._numberOfStudents; } get level() { return this._level; } quickFacts() { console.log(`${this._name} educates ${this._numberOfStudents} students at the ${this._level} school level.`); } static pickSubstituteTeacher(substituteTeachers) { let num = Math.floor(substituteTeachers.length * Math.random()); console.log(substituteTeachers[num]); } 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, 'primary'); this._pickupPolicy = pickupPolicy; } get pickupPolicy() { return this._pickupPolicy; } } class HighSchool extends School { constructor(name, numberOfStudents, sportsTeams) { super(name, numberOfStudents, 'high'); this._sportsTeams = sportsTeams; } get sportsTeams() { console.log(this._sportsTeams); } } const lorraineHansbury = new PrimarySchool('Lorraine Hansbury', 25, 'Students must be picked up by a parent, guardian, or a family member over the age of 13.'); lorraineHansbury.quickFacts(); School.pickSubstituteTeacher(['Joan', 'Ben', 'John', 'Marvin']); const alSmith = new HighSchool('Al E. Smith', 415, ['Baseball', 'Basketball', 'Volleyball', 'Track and Field']); alSmith.sportsTeams;