FAQ: Classes - Inheritance V

This community-built FAQ covers the “Inheritance V” 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 V

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!

/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:25
get certifications()
^

RangeError: Maximum call stack size exceeded
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:25:21)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)

I have got the above message on the output screen although the code run fine. Can someone explain about this?

It’s like getters must be made before corresponding methods can work.

console.log(nurseOlynyk._certifications[2]) of genetics
This line of code generates the correct answer to the activity on screen 10 but doesn’t lead to correct response on webpage.

nurseOlynyk.addCertification(‘Genetics’);
console.log(nurseOlynyk.certifications); //[ ‘Trauma’, ‘Pediatrics’, ‘Genetics’ ]

1 Like

No need to put the underscore because we are pushing the new string into the parameter, certifications.

1 Like

Thanks, i’ll may check into that later. Having to deal with some practical stuffs/other stuff so haven’t look back into Javascript on CodeAcademy in a few weeks. That sounds like a good catch.

Don’t be mislead into thinking the underscores are of no particular significance. Architecturally they are vitally important and cannot for a second be written off.

We’re in a different domain once setters and getters are introduced. Forget that we can sort of do the same thing without them. With them we have another level of functionality. Not just another level, a whole universe of inspection, validation, composition, reporting, &c. Not the sort of thing we would expect to find in a property definition.

Consider,

 this.prop = value;
 // ...
 get prop () {
     return this._prop;
 }
 set prop (value) {
     // validate value
     this._prop = value;
 }

We’ve essentially created a backing variable using the very setter intended to work with one. The getter will now work as expected.

Perhaps you can explain why we cannot perform both operations at once? There seems to be some restriction in place. Any ideas?


Proof the setter is run…

 > class a {
     constructor(value) {
       this.prop = value;
     }
     get prop () {
       return this._prop;
     }
     set prop (value) {
       // validate value
       this._prop = value;
    }
  }
<- undefined
 > b = new a('funny')
<- > a {_prop: "funny"}
 > b._prop
<- "funny"

At this point we confirm the endpoint. Now we want to validate the data before it reaches the endpoint.

1 Like

I wasn’t writing off the underscores. The comment of pratical was in reference to needing to deal with some real life issues before getting back to codeacademy problem and finding a solution. Thanks for your assistance.

1 Like

Why is this not registering as correct for the first exercise? The solution looks exactly the same.

class Nurse extends HospitalEmployee {
constructor(name, certifications) {
super(name);
this._certifications = certifications;
}
get certifications() {
return this._certifications;
}
}

1 Like

it seems like I am having the same issue it is very frustrating any answers anyone ?

1 Like

My biggest issue going through codeacademy thus far has nothing to do with explanations. Actually, this question is rather easy. The way they present the questions are very confusing where I actually view the solution to understand the question.

Should never be like that. For example, this questions specfically states properties and methods but to a new developer can be confusing because thought process is … do we create new properties on the new object or is it already understood as it’s being inherited through extends.

So, I wish CodeAcademy would go through some of their questions and just ask the question and not convolute everything.

Other than that, no qualms with CA.