Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created March 27, 2021 14:41
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/8ebcd93f49da5bff6ad8c5b064f647a9 to your computer and use it in GitHub Desktop.
Save codecademydev/8ebcd93f49da5bff6ad8c5b064f647a9 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(value) {
if(value.isNaN()) {
console.log('Invalid input: numberOfStudents must be set to a Number.')
} else {
this._numberOfStudents = value; }
}
quickFacts() {
console.log(`${this._name} educates ${this._numberOfStudents} students at the ${this._level} school level.`)
}
static pickSubstituteTeachers(substituteTeachers) {
const randomNum = Math.floor(Math.random()*substituteTeachers.length);
return substituteTeachers[randomNum];
}
}
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() {
console.log(this._sportsTeams);
}
}
const DumbCollege = new PrimarySchool('Dumb College', 'blah', 'Students must be picked up by a Parent, guardian, or a family member over the age of 13.');
const sub = School.pickSubstituteTeachers(['Jamal Crawford', 'Lou Williams', 'J. R. Smith', 'James Harden', 'Jason Terry', 'Manu Ginobli']);
const StupidHigh = new HighSchool('Stupid High', 'd', ['Baseball', 'Basketball', 'Volleyball', 'Track and Field']);
DumbCollege.quickFacts();
console.log(DumbCollege.pickupPolicy)
console.log()
StupidHigh.quickFacts();
console.log('Sports Teams:')
console.log(StupidHigh.sportsTeams)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment