Skip to content

Instantly share code, notes, and snippets.

@debonx
Created September 3, 2019 11:39
Show Gist options
  • Save debonx/4b9d255f4c62237f964434e9c7832838 to your computer and use it in GitHub Desktop.
Save debonx/4b9d255f4c62237f964434e9c7832838 to your computer and use it in GitHub Desktop.
Simple JavaScript class to classify schools.
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