5. Method calls

I’m following the exercise of the method calls lesson of the classes module, and logging the name of ‘surgeonCurry’ to the console:
console.log(surgeonCurry.name());
gives the following error:

/home/ccuser/workspace/learn-javascript-classes-classes-methods/main.js:28
console.log(surgeonCurry.name());
                         ^

TypeError: surgeonCurry.name is not a function

I cannot see any obvious error in the code.

The class is defined as follows:

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;
  }
}

Your code doesn’t produce that error message, the problem isn’t included, or at least, it doesn’t show how the problem happens

Thanks for your fast response.
When calling the getter method from the instance, I didn’t realize that there should be no parentheses after the getter name: i.e.
surgeonCurry.name works, but surgeonCurry.name() throws an error.

I’m receiving the same error as well. The instruction checkmarks clear no problem, but this exact same error is occurring with me and the results are not printing to console.

2 Likes

A post was split to a new topic: 5. method call

console.log(surgeonCurry.remainingVacationDays);

you should not put () after surgeonCurry.remainingVacationDays in your console.log