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 trialTiffany White
5,373 PointsI don't understand what I am doing wrong.
I am doing exactly what MDN said I should do and the example from Treehouse. What I am doing wrong here? It says I don't need the firstName
or lastName
properties but when I remove them it tells me to add them. I'm lost.
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
Tiffany White
5,373 PointsI believe so Ryan Zimmerman
Ryan Zimmerman
3,854 PointsSo I don't know the exact challenge and I don't want to send you in the wrong direction but I would think it is something like this.
function Person (firstName, lastName) { this.firstName: firstName, this.lastName: lastName }
var Teacher = new Person();
Person.prototype.fullName = function () { return this.firstName + ' ' + this.lastName; }
Teacher.prototype.roomNumber = //how ever you want to build it
Tiffany White
5,373 PointsI need to use the call()
method for prototypal inheritance/chaining. Thanks anyway.
Ryan Zimmerman
3,854 PointsRyan Zimmerman
3,854 PointsSo are you creating a prototype of Person for which Teacher will be a new Person?