How to overwrite a preset value in a child class

Hello, so I created an instance, doc of class Doctor , and when I created it I passed it 14 for the remainingVacationDays property .
Why is it, when I log doc.remainingVacationDays it prints out 20 ? Shoudn’t it log 14 ? I know 20 comes from the parent’s class constructor, but why can’t I overwrite this number in the instance ?

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 Doctor extends HospitalEmployee{
    this._insurance = insurance;

const doc = new Doctor('doc',14,true); 
console.log(doc.remainingVacationDays); // Logs 20 .

Now , I know if I write Doctor class constructor like below it logs 14, but what if I want to log out the value in the instance ?

class Doctor extends HospitalEmployee{
    this._remainingVacationDays = 14;
    this._insurance = insurance;
1 Like

Hello, @micro1086421766. Welcome to the forum.

Your constructor only takes one parameter, name. Adding a second argument when you instantiate a new doctor object does nothing. The first argument becomes the value of the name parameter, and anything after that argument is ignored. You could modify your constructor to take a vacation days parameter, and then assign that value instead of the arbitrary number 20.

I believe it is in the instructions to write that property into the constructor with a preset value of 20.

As for it doing nothing, that is not the case. It is an instance variable whether given in the parameters or hard coded into the constructor.

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


[ 'Trauma', 'Pediatrics', 'Genetics' ]

Yes. The instructions do call for the preset value of 20. I was referring to his Doctor class that he added in addition to the exercise instructions:

Passing the additional remainingVacationDays parameter to the parent constructor that only accepts the name parameter does not overwrite the assignment of 20 to the remainingVacationDays property.

The instructions stipulate having that property in a Doctor class constructor.


  • properties: _name , _remainingVacationDays (set to 20 inside constructor() ), _insurance
  • methods: .takeVacationDays()

Yes, as extra practice. The OP is trying to overwrite the arbitrary assignment of 20 remainingVacationDays by passing 14 as an additional argument. The HospitalEmployee constructor does not take a remainingVacationDays parameter, so passing the argument does nothing, and 20 days is assigned. I was explaining that it is possible to re-write the constructor to take a remainingVacationDays parameter if he wanted to since he’s already passed all of the required steps.


Ah, so the concern has been passing it to super, and somehow that escaped me. D’oh!

The course author is recommending that we override the super attribute, and instantiate it within this class. The attribute will be present, but not inheriting from the class.

Given the context, that would explain why the Doctor has its own .takeVacationDays() method, since the Doctor class attribute would not be in parent context if we ran the inherited method.

My silly question now is, “can we trick the method of the parent class to act upon the override value our subclass has on the attribute?” Needs testing in an unambiguous environment.


I wrote this and it worked:

class Doctor extends HospitalEmployee {
this._remainingVacationDays = 14

const doc = new Doctor(‘Doc’);
console.log(doc.remainingVacationDays); //Output: 8