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 trialMicah Dunson
34,368 PointsUnable to properly modify code to inherit
the code asks to use the call() and when I do I get the error message "You don't need to set the firstName or lastName properties, the Person.call will handle that!"
to modify 'Teacher' to inherit from 'Person' I'm doing: Person.call(this, firstName, lastName);
I am unsure what is wrong about this code
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.fullName = function() {
return this.firstName + " " + this.lastName;
};
function Teacher(firstName, lastName, roomNumber) {
Person.call(this, firstName , lastName)
this.firstName = firstName;
this.lastName = lastName;
this.room = roomNumber;
}
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHi Michah,
The first part of the challenge wants you to .call the Person constructor in the Teacher constructor. You are very close, but you do not need the two lines for the this.firstName
or this.lastName
as that will be handled by the Person Constructor. So Task 1 should look like this:
function Teacher(firstName, lastName, roomNumber) {
Person.call(this, firstName, lastName);
this.room = roomNumber;
}
For the second part of the challenge, you just have to add the line of code so that the Teacher can "inherit" from the Person.
function Teacher(firstName, lastName, roomNumber) {
Person.call(this, firstName, lastName);
this.room = roomNumber;
Teacher.prototype = Object.create(Person.prototype);
I'm not sure I can fully explain this part well. It's basically allowing the Teacher to use the Person. Andrew explains it in the previous video (the one before the challenge) at about 2:30.
I don't know where or why you have a return
statement there. The challenge didn't ask for anything to be returned, and the challenges are very specific in what you can and can't put in in order to pass.
Hope this makes sense and helps. Keep Coding! :)
Micah Dunson
34,368 PointsMakes perfect sense. Thanks man! I knew I was missing something basic. I hear ya on the exercises.