Created
November 3, 2022 12:24
-
-
Save CodeLikeAGirl29/a688c1ba51470825d8937289a57fc07f to your computer and use it in GitHub Desktop.
For Codecademy's Intermediate JavaScript project - School Catalogue
This file contains hidden or 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 = ['primary', 'middle', 'high']; | |
this._numberOfStudents = numberOfStudents; | |
} | |
get name() { | |
return this._name; | |
} | |
get level() { | |
return this._level; | |
} | |
get numberOfStudents() { | |
return this._numberOfStudents; | |
} | |
set numberOfStudents(input) { | |
if (typeof input === 'Number') { | |
this._numberOfStudents = input; | |
} else { | |
console.log('Invalid input: numberOfStudents must be set to a Number.') | |
} | |
} | |
quickFacts() { | |
console.log(`${this.name} educates ${this.numberOfStudents} at the ${this.level} school level`) | |
} | |
static pickSubstituteTeacher(substituteTeachers) { | |
const randomInteger = Math.floor(substituteTeachers.length * Math.random()); | |
return substituteTeachers[randomInteger]; | |
} | |
} | |
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 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']); | |
const alSmith = new HighSchool('Al E. Smith', 123, ['Baseball', 'Basketball', 'Volleyball', 'Track and Field']); | |
console.log(alSmith.sportsTeams); | |
alSmith.quickFacts(); | |
const test = new School('test', 'primary', 1); | |
test.quickFacts(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment