Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSIYUOM MAMO
6,818 PointsYou're going to modify the Teacher code to inherit from the Person. First, in the Teacher constructor function, call the
please please help I have been try a lot but I cant,t pass function person(firstNam,lastnam){ this.firstName=firstName; this.lastName=lastName;
person.prototype.fullname=function(){ return this.firstName+" "+ this.lastname;
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.fullName = function() {
return this.firstName + " " + this.lastName;
};
function Teacher(firstName, lastName, roomNumber) {
this.firstName = firstName;
this.lastName = lastName;
this.room = roomNumber;
}
2 Answers
Erik Nuber
20,629 PointsThe first part asks you to call the Person function and pass in the common attributes.
We no longer will need this.firstName or this.lastName as the Person function will take care of that for you.
So we call as below.
function Teacher(firstName, lastName, roomNumber) {
this.room = roomNumber;
Person.call(this, firstName, lastName);
}
Then you are asked to set up a prototype chain for the Teacher prototype to inherit the Person prototype
Teacher.prototype = Object.create(Person.prototype);
If you want a class to inherit the methods from another class, you need to use Object.create(), in this case, this way.
Steven Parker
231,275 PointsGive a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime.
  ― Maimonides
James Ackerman
14,099 PointsI HATE JavaScript. None of this makes any sense to me.
Erik Nuber
20,629 PointsConstructor functions are using prototypes can be confusing. It just takes some practice. I would recommend Javascript and Jquery by Jon Duckett. A very easy to understand book. It just takes patience and persistence.
I can explain my answer better if you would like.
Steven Parker
231,275 PointsSteven Parker
231,275 PointsIt doesn't look like you've written any code yet.
At least give it a good-faith attempt. If you have no idea where to start, re-watch the video on inheritance.