-
-
Save codecademydev/a52d9fd60f70acda15ffdecec577ed32 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
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(typeof newNumberOfStudents === 'number') { | |
this._numberOfStudents = newNumberOfStudents; | |
} else { | |
console.log('Invalid input: numberOfStudents must be set to a Number.'); | |
} | |
} | |
quickFacts() { | |
console.log(`${this._name} educates ${this._numberOfStudents} students at the ${this._level} school level.`) | |
} | |
static pickSubstituteTeacher(substituteTeachers) { | |
const randomNumber = Math.floor(substituteTeachers.length * Math.random()); | |
return substituteTeachers[randomNumber]; | |
} | |
} | |
class PrimarySchool extends School { | |
constructor(name, numberOfStudents, pickUpPolicy) { | |
//including numberOfStudents because it was set(setter method) as changeable data, | |
// 'primary is included in super and not in this._level because it's value is set directly in class and not being passed via new class | |
// Any property that is defined in the superclass must be passed also into Super(). | |
//Otherwise the property will not be created in the child class, and thus will not be present in the objects you create with it. | |
super(name, 'primary', numberOfStudents); | |
this._pickUpPolicy = pickUpPolicy; | |
} | |
get pickUpPolicy() { | |
return this._pickUpPolicy; | |
} | |
} | |
class HighSchool extends School { | |
constructor(name, numberOfStudents, sportsTeams) { | |
super(name, 'high school', numberOfStudents); | |
this._sportsTeams = sportsTeams; | |
} | |
get sportsTeams() { | |
return this._sportsTeams; | |
} | |
} | |
const lorraineHansbury = new PrimarySchool('Lorraine Hansbury', 514, 'Students must be picked up by a parent, guardian, or a family member over the age of 13.'); | |
lorraineHansbury.quickFacts(); | |
const sub = School.pickSubstituteTeacher(['Jamal Crawford', 'Lou Williams', 'J. R. Smith', 'James Harden', 'Jason Terry', 'Manu Ginobli']); | |
console.log(School.pickSubstituteTeacher); | |
const alSmith = new HighSchool('Al E. Smith', 415, ['Baseball', 'Basketball', 'Volleyball', 'Track and Field']); | |
//call alSmith.sportsTeams without () because it's calling a getter method and getter methods have the same syntax as a property object.property | |
console.log(alSmith.sportsTeams); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment