Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created September 24, 2020 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/c2504ae6edb66d2ad2a9401e32493c52 to your computer and use it in GitHub Desktop.
Save codecademydev/c2504ae6edb66d2ad2a9401e32493c52 to your computer and use it in GitHub Desktop.
Codecademy export
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(num) {
if (Number.isNaN(num)) {
console.log('Invalid input: numberOfStudents must be set to a Number.');
} else {
return this._numberOfStudents = num;
}
}
quickFacts() {
console.log(`${this.name} educates ${this.numberOfStudents} students at the ${this.level} level.`)
}
static pickSubstituteTeacher(substituteTeachers) {
let tlength = substituteTeachers.length;
console.log(substituteTeachers[Math.floor(tlength * Math.random())]);
return substituteTeachers[Math.floor(tlength * Math.random())];
}
}
class PrimarySchool extends School {
constructor(name, num, pickupPolicy) {
super(name, 'primary');
this.numberOfStudents = num; // invoke the setter method
this._pickupPolicy = pickupPolicy;
}
/*
class PrimarySchool extends School {
constructor(name, numberOfStudents, pickupPolicy) {
super(name, 'primary', numberOfStudents);
this._pickupPolicy = pickupPolicy;
}*/
get pickupPolicy() {
return this._pickupPolicy;
}
}
class Middle extends School {
constructor(name, numberOfStudents) {
super(name, 'Middle', numberOfStudents);
}
}
class High extends School {
constructor(name, numberOfStudents, sportsTeam) {
super(name, 'high', numberOfStudents);
this._sportsTeam = sportsTeam;
}
get sportsTeam() {
return console.log(this._sportsTeam);
}
}
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');
lorraineHansbury.quickFacts();
School.pickSubstituteTeacher(['Jamal Crawford', 'Lou Williams', 'J. R. Smith', 'James Harden', 'Jason Terry', 'Manu Ginobli']);
lorraineHansbury.numberOfStudents(12);
const alSmith = new High('Al E. Smith', 415, ['Baseball', 'Basketball', 'Volleyball', 'Track and Field']);
alSmith.sportsTeam;
const johnson = new Middle('Johnson Junior High School', 312);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment