FAQ: Classes - Inheritance IV


#1

This community-built FAQ covers the “Inheritance IV” exercise from the lesson “Classes”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise Inheritance IV

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

I did everything right and the checkboxes lit up but I see an error. Is this what is supposed to happen?

// code begins here
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); // I did this right and it took me to the next task
console.log(nurseOlynyk.remainingVacationDays()); // I did this right but instead of printing something I got an error, but it still said I got it right.

// here is the error code
/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-iv/main.js:29
console.log(nurseOlynyk.remainingVacationDays());
^

TypeError: nurseOlynyk.remainingVacationDays is not a function
at Object. (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-iv/main.js:29:25)
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


#3

Nevermind. I figured it out. It was the ().

Even though I included it which I should not have it still said it was the right answer. I went back in, reset and asked for the solution and that’s how I found out that is should not have included the ().


#4
console.log(nurseOlynyk.remainingVacationDays);

#5

Thanks! I think I figured it out just a few seconds after and tried to delete my post :slight_smile: