@seangarvey/classOfHospitalEmployee.js
ES6

Written in ES6, this code creates a Super Class of HospitalEmployee and then a SubClass of Nurse and then performs methods on Nurse SubClass

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class HospitalEmployee {
  constructor(name) {
    this._name = name;
    this._remainingVacationDays = 20;
  }
  
  get name() {
    return this._name;
  }
  
  get remainingVacationDays() {
    return this._remainingVacationDays;
  }
  
  takeVacationDays(daysOff) {
    this._remainingVacationDays -= daysOff;
  }
  
  static generatePassword() {
    const password = [[],[],[],[]];
    password[0] = Math.floor(Math.random() * 9); 
    password[1] = Math.floor(Math.random() * 9); 
    password[2] = Math.floor(Math.random() * 9); 
    password[3] = Math.floor(Math.random() * 9); 
    return password.join('');
  }
}

class Nurse extends HospitalEmployee {
  constructor(name, certifications) {
    super(name);
    this._certifications = certifications;
  } 
  
  get certifications() {
    return this._certifications;
  }
  
  addCertification(newCertification) {
    this.certifications.push(newCertification);
  }
}

const nurseOlynyk = new Nurse('Olynyk', ['Trauma','Pediatrics']);
nurseOlynyk.takeVacationDays(5);
console.log('Remaining Vacation Days: ' + nurseOlynyk.remainingVacationDays + '.');
nurseOlynyk.addCertification('Genetics');
console.log('Certifications include: ' + nurseOlynyk.certifications.join(', ') + '.');
console.log('Password: ' + HospitalEmployee.generatePassword());
Babel Compiler v6.4.4 Copyright (c) 2014-2015 Sebastian McKenzie