Guest User

Untitled

a guest
Apr 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. class School{
  2. constructor(name, level, numberOfStudents){
  3. this._name = name;
  4. this._level = level;
  5. this.numberOfStudents = numberOfStudents;
  6. }
  7. get name(){
  8. return this._name;
  9. }
  10. get level(){
  11. return this._level;
  12. }
  13. set numberOfStudents(number){
  14. if(typeof number === 'number'){
  15. this._numberOfStudents = number;
  16. }else{
  17. console.log(`Invalid input: numberOfStudents must be set to a Number.`);
  18. }
  19. }
  20. get numberOfStudents(){
  21. return this._numberOfStudents;
  22. }
  23.  
  24.  
  25. quickFacts(){
  26. return `${this._name} educates ${this._numberOfStudents} students at the ${this._level} school level`;
  27. }
  28.  
  29. static pickSubstituteTeacher(substituteTeachers){
  30. let teacherIndex = Math.floor(Math.random() * substituteTeachers.length);
  31. return substituteTeachers[teacherIndex];
  32. }
  33. }
  34.  
  35. class PrimarySchool extends School{
  36. constructor(name, numberOfStudents, pickupPolicy){
  37. super(name, 'primary', numberOfStudents);
  38.  
  39. this._pickupPolicy = pickupPolicy;
  40. }
  41. get pickupPolicy(){
  42. return this._pickupPolicy;
  43. }
  44. }
  45.  
  46. class HighSchool extends School{
  47. constructor(name, numberOfStudents, sportsTeams){
  48. super(name, 'high', numberOfStudents);
  49. this._sportsTeams = sportsTeams;
  50. }
  51. get sportsTeams(){
  52. return this._sportsTeams;
  53. }
  54. }
  55.  
  56. 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.' );
  57. //console.log(lorraineHansbury.name);
  58. //console.log(lorraineHansbury.numberOfStudents);
  59. //console.log(lorraineHansbury.pickupPolicy);
  60. //console.log(lorraineHansbury.quickFacts());
  61.  
  62. //console.log(School.pickSubstituteTeacher(['Jamal Crawford', 'Lou Williams', 'J. R. Smith', 'James Harden', 'Jason Terry', 'Manu Ginobli']));
  63.  
  64. const alSmith = new HighSchool('Al E. Smith', 415, ['Baseball', 'Basketball', 'Volleyball', 'Track and Field']);
  65.  
  66. console.log(alSmith.sportsTeams);
Add Comment
Please, Sign In to add comment