-
-
Save codecademydev/1c9fc65de66828a4d2a87cf855300787 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 (isNaN(newNumberOfStudents)){console.log('Invalid input: numberOfStudents must be set to a Number.');} | |
else {this._numberOfStudents = newNumberOfStudents} | |
} | |
quickFacts(){ | |
console.log(`${this._name} educates ${this._numberOfStudents} students at the ${this._level} school level.`) | |
} | |
static pickSubstituteTeacher(substituteTeachers){ | |
const randInt = Math.floor(Math.random() * substituteTeachers.length); | |
return substituteTeachers[randInt]; | |
} | |
} | |
class PrimarySchool extends School { | |
constructor(name, numberOfStudents, pickupPolicy, averageTestScores){ | |
super(name, 'primary', numberOfStudents); | |
this._pickupPolicy = pickupPolicy; | |
this._averageTestScores = []; | |
} | |
get pickupPolicy(){ | |
return this._pickupPolicy; | |
} | |
get averageTestScores(){ | |
return this._averageTestScores; | |
} | |
averageTestScores(){ | |
return this._averageTestScores.reduce((a, b) => {a + b}) / this._averageTestScores.length; | |
} | |
getScore(newScore){ | |
this._averageTestScores.push(newScore); | |
} | |
} | |
class HighSchool extends School { | |
constructor(name, numberOfStudents, sportsTeams){ | |
super(name, 'high', numberOfStudents); | |
this._sportsTeams = sportsTeams; | |
} | |
get sportsTeams(){ | |
return this._sportsTeams; | |
} | |
} | |
class SchoolCatalogue extends School { | |
constructor(){ | |
super(); | |
} | |
} | |
const lorraineHan = new PrimarySchool('Lorraine Hansbury', 515, 'Students must be picked up by a parent, guardian, or a family member over the age of 13.'); | |
console.log(lorraineHan.name); | |
lorraineHan.quickFacts(); | |
lorraineHan.averageTestScores(); | |
//console.log(lorraineHan.averageTestScore); | |
console.log(lorraineHan.numberOfStudents); | |
const subTeacher = School.pickSubstituteTeacher(['Jamal Crawford', 'Lou Williams', 'J.R. Smith', 'James Harden', 'Jason Terry', 'Manu Genobli']); | |
console.log(subTeacher); | |
const alSmith = new HighSchool('Al E. Smith', 415, ['Baseball', 'Basketball', 'Volleybal', 'Track and Field']); | |
console.log(alSmith.sportsTeams); | |
console.log(alSmith.numberOfStudents); | |
const nyCatalogue = new SchoolCatalogue(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment