Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class School {
- constructor(name, level, numberOfStudents) {
- this._name = name;
- this._level = level;
- this._numberOfStudents = 0;
- }
- get name() {
- return this._name;
- }
- get level() {
- return this._level;
- }
- get numberOfStudents() {
- return this._numberOfStudents;
- }
- quickFacts() {
- console.log(`${this._name} educates ${this._numberOfStudents} at the ${this._level} school level.`)
- }
- static pickSubstituteTeacher(substituteTeachers) {
- const teacherNumber = Math.floor(Math.random() * substituteTeachers.length);
- return substituteTeachers[teacherNumber];
- }
- set numberOfStudents(newStudent) {
- if (typeof newStudent === 'Number') {
- this._numberOfStudents = newStudent;
- } else {
- console.log(`Invalid input: ${this._numberOfStudents} must be set to a Number`);
- }
- }
- }
- 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 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();
- School.pickSubstituteTeacher(['Jamal Crawford', 'Lou Williams', 'J.R. Smith', 'James Harden', 'Jason Terry', 'Manu Ginobli']);
- console.log(School.substituteTeachers);
- const alSmith = new HighSchool('Al E. Smith', 415, ['Baseball', 'Basketball', 'Volleyball', 'Track and Field']);
- alSmith.sportsTeams;
Add Comment
Please, Sign In to add comment