Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created March 28, 2021 16:36
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/b0fbc734b2486d32b55ab641bc7cb0e1 to your computer and use it in GitHub Desktop.
Save codecademydev/b0fbc734b2486d32b55ab641bc7cb0e1 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) {
this._numberOfStudents = value
}
quickFacts() {
if (this._numberOfStudents >= 0 ) {
return `${this._name} educates ${this._numberOfStudents} students at the ${this._level} school level.`
} else {
return `${this._name} educates ??? 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() {
return this._sportsTeams;
}
}
const DumbCollege = new PrimarySchool('Dumb College', 40, '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', 40, 'Baseball, Basketball, Volleyball, Track and Field');
const college = new School('Codecademy', 'Expert', `${this._numberOfStudents}`)
college.numberOfStudents =
console.log(college.quickFacts())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment