Inheritance V

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;

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

const nurseOlynyk = new Nurse('Olynyk', ['Trauma','Pediatrics']);


// Why is the output of the last line (console.log(nurseOlynyk.certifications):wink: a number and not the array with the strings?

Thank you very much!


because of what you do here:

this._certifications = this._certifications.push(newCertification);

Any ideas what you do wrong there? Take a minute to think about it, let me know if you need more help


Ah ok, yeah I assign a new value and overwrite the old one instead of adding another string to my array. Still, I would think that the output of console.log(nurseOlynyk.certifications) would then be [‘Genetics’] and not a number?



read the docs:

it explains how the method works. So the person who wrote the push method to decide to return the new length of the array (after adding the element)

by doing variable_name = method_call() you store the returned result in the variable_name


Aha sure, now I understand. I overwrote my variable with the length of the array^^
Thanks again.


the problem with returning an array would be that you then have a duplicate array, which is very memory inefficient. And the length seems a valuable thing to return, better then undefined