7. Inheritance II / Learn JS : Classes


#1

Hi all !
ERROR MESSAGE SyntaxError: Unexpected token }


https://www.codecademy.com/courses/learn-javascript-classes/lessons/classes/exercises/inheritance-ii?action=lesson_resume&course_redirect=introduction-to-javascript
When you use inheritance do you have to write both parent class and child class

  1. on the same page ?
  2. one inside the other or one next to the others ?

Wahooo ! I thought that inheritance was
"a tool developers use to decrease the amount of code they need to write." ?
thanks for help !


#2

debugging from an image is really difficult, please copy paste your code to the forum

same page or same file? The answer to this question is not so straightforward as it might seem. This depends if you are doing front-end or back-end web development. In case of front-end, you can write them in separate files, but then you would have to use something like webpack to produce a single output file. You will very likely need webpack for es6 anyway, given browser support isn’t good enough yet

next/after each other, you can’t inherit from something which isn’t fully defined yet.

you can also nest (inside) classes. But you can’t inherit from something which you are in the midst of defining.


#3

Here is the code . (I put the adress)

class HospitalEmployee {
constructor(name) {
  this.name=name;} 
  get name (){return this._name;}
  get remaningVacationDays (){return this._remainningVacationDays;}
  takeVacationDays(){this._takeVacationDays;} }

class Doctor {
constructor(name, remainingVacationDays, insurance){
this._name=name;
this._remainingVacationdays=20;
this._insurance=insurance;}
 get name (){return this._name;}
  get remaningVacationDays (){return this._remainningVacationDays;}
  takeVacationDays(){this._takeVacationDays;} }

class Nurse {
 constructor (name,remainingVacationDays, certifications ) {
 this._name=name;
 this._remainingVacationdays=20;
 this._certifications=certifications;}
   get name (){return this._name;}
  get remaningVacationDays (){return this._remainningVacationDays;}
  takeVacationDays(){this._takeVacationDays;}
  addCertification() }

#4

last line:

addCertification() }

your addCertification is half-cooked, its not a complete function. Either complete it or remove it for the time being if you don’t know what do with it yet


#5

Thanks a lot Stetim . It works .

But in general I m surprised because I thought when you inherit , code should be shorter .

thanks !


#6

depends what you compare it with

i think you will work towards cleaning the code in the next few exercises, starting really verbose and see how you can optimize the code


#7

Oh Ok . thanks Stetim94 for your explanation !


#8

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