Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created April 17, 2019 05:07
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/5f71c387de147c9c15b545ab356912e0 to your computer and use it in GitHub Desktop.
Save codecademydev/5f71c387de147c9c15b545ab356912e0 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 numberOfStudent(num) {
if (typeof num === number) {
this._numberOfStudents = num;
} 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) {
const randomNumber = math.floor(math.random()*substituteTeachers.length);
return substituteTeachers[randomNumber];
}
}
class PrimarySchool extends School {
constructor(name, numberOfStudents, pickupPolicy) {
super(name, 'primary', numberOfStudents);
this._pickupPolicy = pickupPolicy;
}
get pickupPolicy() {
return this._pickupPolicy;
}
}
class MiddleSchool extends School {
constructor(name) {
super(name);
}
}
class HighSchool extends School {
constructor(name, numberOfStudents, sportsTeams) {
super(name, 'high', numberOfStudents);
this._sportsTeams = sportsTeams;
}
get sportsTeams() {
return this._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.');
lorraineHansbury.quickFacts();
lorraineHansbury.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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment