Inheritance V


#1

https://www.codecademy.com/courses/learn-javascript-classes/lessons/classes/exercises/inheritance-v?action=resume_content_item&course_redirect=introduction-to-javascript

I can’t seem to get past this error: ‘Did you create a getter for the certifications property?’

even thpugh I created it as:

class Nurse {
  constructor(name, remainingVacationDays) {
    this._name = name;
    this._remainingVacationDays = 20;
    this._certifications = certifications;
  }
  
  get certifications() {                                    //this is where the problem is
    return this._certifications;
  }
  
   addCertification(newCertification) {
    newCertification.push(this._certification);
  }
  
  takeVacationDays() {
    }
  }

#2

how come your Nurse class isn’t extending the HospitalEmployee class? a nurse is a hospital employee

this exercise is called inheritance V, and then you have no inheritance? If i reset the exercise i get this code:

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) {
    super(name);
    this._certifications = certifications;
  } 
}

const nurseOlynyk = new Nurse('Olynyk', ['Trauma','Pediatrics']);
nurseOlynyk.takeVacationDays(5);
console.log(nurseOlynyk.remainingVacationDays);

which does use inheritance. Its not recommended to remove code from an exercise, this might cause problems with exercise validation.


#3

Okay I pasted only a portion of it. This the whole code:

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 {
constructor(name, remainingVacationDays) {
this._name = name;
this._remainingVacationDays = 20;
this._certifications = certifications;
}

get certifications() {
return this._certifications;
}

addCertification(newCertification) {
newCertification.push(this._certification);
}

takeVacationDays() {
}
}

class Nurse extends HospitalEmployee {
constructor(name, certifications) {
super(name);
this._certifications = certifications;
}
}

const nurseOlynyk = new Nurse(‘Olynyk’, [‘Trauma’,‘Pediatrics’]);
nurseOlynyk.takeVacationDays(5);
console.log(nurseOlynyk.remainingVacationDays);
nurseOlynyk.addCertification(‘Genetics’);
console.log(nurseOlynyk.certifications);

I wasn’t sure if I was to edit the extended Nurse class or create a new one as per instruction one. So I added another class.

The error below is the only one persisting so I went on ahead and did the others:
‘Did you create a getter for the certifications property?’

And this one though I ignored it in the previous exercise and it worked:
/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:46
}
^
SyntaxError: Identifier ‘Nurse’ has already been declared


#4

the syntax error clearly indicates that you should only have a single Nurse class. You should have added methods (like the getter) to the already existing nurse class


#5

Figured it out. Changed this line

addCertification(newCertification) {
newCertification.push(this._certifications);
}

to,

addCertification(newCertification) {
this._certifications.push(newCertification);
}