-
-
Save codecademydev/30b814267a87c315ac80fca0de9410ea to your computer and use it in GitHub Desktop.
Codecademy export
This file contains 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
// Parent class: School. | |
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(newNumberOfStudents){ | |
if(isNaN(newNumberOfStudents)){ | |
console.log('Invalid input: numberOfStudents must be set to a Number.'); | |
}else{ | |
return this._numberOfStudents = newNumberOfStudents; | |
} | |
} | |
quickFacts(){ | |
console.log(`${this._name} educates ${this._numberOfStudents} students at the ${this._level} school level.`); | |
} | |
static pickSubstituteTeacher(substituteTeachers){ | |
substituteTeachers = []; | |
let randomNumber = Math.floor(Math.random() * substituteTeachers.length); | |
return substituteTeachers[randomNumber]; | |
} | |
} | |
//////////////////////////////////////// | |
// Child class: Primary School | |
class Primary extends School { | |
constructor(name, level, numberOfStudents, pickupPolicy){ | |
super(name, 'Primary', numberOfStudents); | |
this._pickupPolicy = pickupPolicy; | |
} | |
get pickupPolicy(){ | |
return this._pickupPolicy; | |
} | |
} | |
//////////////////////////////////////// | |
// Child class: Middle School | |
class Middle extends School { | |
constructor(name, level, numberOfStudents){ | |
super(name, 'Middle', numberOfStudents); | |
} | |
} | |
//////////////////////////////////////// | |
// Child class: High School | |
class High extends School { | |
constructor(name, numberOfStudents, sportsTeams){ | |
super(name, 'High', numberOfStudents); | |
this._sportsTeams = sportsTeams; | |
} | |
get sportsTeams(){ | |
return this._sportsTeams; | |
} | |
} | |
//////////////////////////////////////// | |
// TESTS: | |
const lorraineHansbury = new Primary('Lorraine Hansbury', 514, 'Students must be picked up by a parent, guardian, or a family member over the age of 13.'); | |
console.log(lorraineHansbury); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment