Created
September 3, 2019 11:39
-
-
Save debonx/4b9d255f4c62237f964434e9c7832838 to your computer and use it in GitHub Desktop.
Simple JavaScript class to classify schools.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 name(){ | |
return this._numberOfStudents; | |
} | |
quickFacts(){ | |
console.log(`${this._name} educates ${this._numberOfStudents} students at the ${this._level} school level.`); | |
} | |
static pickSubstituteTeacher(substituteTeachers){ | |
if(typeof substituteTeachers == 'object'){ | |
let index = Math.floor(Math.random() * substituteTeachers.length); | |
return substituteTeachers[index]; | |
} | |
} | |
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, 'primary', 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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment