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 trial

JavaScript Object-Oriented JavaScript (2015) Prototypal Inheritance Setting Up the Prototype Chain

Tiffany White
Tiffany White
5,373 Points

I 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.

person.js
function Person(firstName, lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
}

Person.prototype.fullName = function() {
 return this.firstName + " " + this.lastName; 
};
teacher.js
function Teacher(firstName, lastName, roomNumber) {
  Person.call(this, firstName, lastName);
  this.firstName = firstName;
  this.lastName = lastName;
  this.room = roomNumber;
}
Ryan Zimmerman
Ryan Zimmerman
3,854 Points

So are you creating a prototype of Person for which Teacher will be a new Person?

2 Answers

Ryan Zimmerman
Ryan Zimmerman
3,854 Points

So 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
Tiffany White
5,373 Points

I need to use the call() method for prototypal inheritance/chaining. Thanks anyway.