Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created March 28, 2021 13:56
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/8822cd2094190a87909b293c33180786 to your computer and use it in GitHub Desktop.
Save codecademydev/8822cd2094190a87909b293c33180786 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 (typeof value === 'number') {
this._numberOfStudents = value;
} else {
console.log('Invalid input...');
}
}
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() {
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 = 'this'
console.log(college.quickFacts())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment