Skip to content

Instantly share code, notes, and snippets.

@codecademydev codecademydev/app.js Secret

Created Apr 8, 2019
Embed
What would you like to do?
Codecademy export
// 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
You can’t perform that action at this time.