JavaScript Class undefined


#1

Hello,

I was following instructions on Class part of JavaScript and couldn’t find what causes ‘undefined’ when I use this method

[console.log(surgeonCurry.takeVacationDays(11));

It’s checked as right answer… is it?
Thanks


class Surgeon {
  constructor(name, department) {
    this._name = name;
    this._department = department;
    this._remainingVacationDays = 20;
  }
  get name(){
    return this._name;
  }
  get department(){
    return this._department;
  }
  get remainingVacationDays(){
    return this._remainingVacationDays;
  }
  takeVacationDays(daysOff){
    this._remainingVacationDays -= daysOff;
  }

}

const surgeonCurry = new Surgeon('Curry', 'Cardiovascular');
const surgeonDurant = new Surgeon('Durant', 'Orthopedics');

console.log(surgeonCurry.name);
console.log(surgeonCurry.department);
console.log(surgeonCurry.remainingVacationDays);
console.log(surgeonCurry.takeVacationDays(11));

#2

Hello -

I’m just learning this as well. The only thing that looks like might be missing is a return in your takeVacationDays() method.

I think it should look like this:

takeVacationDays(daysOff) {
this._remainingVacationDays -= daysOff;
return this._remainingVacationDays;
}

You might be able to just add the return to the beginning of the first line…

Hope this helps a little. Good Luck.


#3

No return needed. The method is a setter acting upon an instance attribute.

You are logging the method’s return value (undefined). Instead of logging that, just invoke the method, then log the remaining days off.