Problems in JavaScript Classes: 5. Method Calls


#1

Hello fellow coders!
A bit of confusion in JavaScript (Classes: 5. Method calls. Here is the link: https://www.codecademy.com/courses/learn-javascript-classes/lessons/classes/exercises/method-calls?action=lesson_resume&course_redirect=introduction-to-javascript .) I am stuck with excersise two:

Call .takeVacationDays() on surgeonCurry, with an input of 3.

My code is currently goes like this:

Code

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’);
console.log(surgeonCurry.name);
console.log(surgeonCurry.takeVacationDays())
const surgeonDurant = new Surgeon(‘Durant’, ‘Orthopedics’);

I this is what appears on my screen when I run it:

Curry
undefined

As well as the pop-up:

Did call the .takeVacationDays() with an input of 3?

The thing is, I’m not really sure what they’re asking me! Ack. Am I supposed to subract 3 from .takeVacationDays()? If so, how do I?

Well, I hope I haven’t been to confusing. Be blunt in your answers! I don’t really care, as long as they are constructive :sweat_smile:

Em


#2

You need to call the function takeVacationDays() and pass 3 as argument. Next you call the getter within a console.log to see the result, like this:

surgeonCurry.takeVacationDays(3);
console.log(surgeonCurry.remainingVacationDays);
// expected result: 17

#3

Hey @fanaticchris,

Thanks so much for the help. It worked! Strange thing though–although the excersises were marked as correct, I got an error message:

Super Long Error Message

Curry
/home/ccuser/workspace/learn-javascript-classes-classes-methods/main.js:29
console.log(surgeonCurry.remainingVacationDays())
^

TypeError: surgeonCurry.remainingVacationDays is not a function
at Object. (/home/ccuser/workspace/learn-javascript-classes-classes-methods/main.js:29:26)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3

Any idea why? Just curious :wink:

Em


#4

Hi @emily_green ,

your call within your console.log includes (). But you are calling this a a parameter of the class, so you dont have to use the ()

wrong:
console.log(surgeonCurry.remainingVacationDays());

correct:
console.log(surgeonCurry.remainingVacationDays);

hope that solves your problem.

Chris


#5

Hi @fanaticchris,
Thanks! Now it really works! You’ve helped me a ton.
Em


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.