Advertisement
karlakmkj

Class - inheritance

Dec 21st, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class HospitalEmployee {
  2.   constructor(name) {
  3.     this._name = name;
  4.     this._remainingVacationDays = 20;
  5.   }
  6.    
  7.   static generatePassword(){
  8.     return Math.floor(Math.random()*10000); //generate a number from 0 to 10,000
  9.   }
  10.  
  11.   get name() {
  12.     return this._name;
  13.   }
  14.  
  15.   get remainingVacationDays() {
  16.     return this._remainingVacationDays;
  17.   }
  18.  
  19.   takeVacationDays(daysOff) {
  20.     this._remainingVacationDays -= daysOff;
  21.   }
  22. }
  23.  
  24. class Nurse extends HospitalEmployee {
  25.   constructor(name, certifications) {
  26.     super(name);
  27.     this._certifications = certifications;
  28.   }
  29.  
  30.   get certifications() {
  31.     return this._certifications;
  32.   }
  33.  
  34.   addCertification(newCertification) {    //method to add newCertification to the certifications array
  35.     this.certifications.push(newCertification);
  36.   }
  37. }
  38.  
  39. const nurseOlynyk = new Nurse('Olynyk', ['Trauma','Pediatrics']);
  40. nurseOlynyk.takeVacationDays(5);
  41. console.log(nurseOlynyk.remainingVacationDays);
  42. nurseOlynyk.addCertification('Genetics');
  43. console.log(nurseOlynyk.certifications);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement