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

Stewart Horsfield
Stewart Horsfield
13,293 Points

Person.call(this, firstName, lastName); is giving contradictory errors

When answering this first question, I entered 'Person.call(this, firstName, lastName); and it was incorrect apparently because I didn't need to add the properties 'firstName' and 'lastName'. So then I removed them and tried again, and that was also incorrect, obviously, but apparently because I needed to enter all three variables in order, which I had done to begin with... I'm really not sure where I'm going wrong here, or if this is a bug, but I would love some clarification either way. Cheers.

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;
}

2 Answers

Emma Davis
Emma Davis
4,760 Points

I am only just doing this lesson but from what I can see, your Teacher constructor should just be (but this might be what you are saying you have tried)

function Teacher(firstName, lastName, roomNumber) {
  Person.call(this, firstName, lastName);
  this.room = roomNumber;
}
Emma Davis
Emma Davis
4,760 Points

In fact, I have just done the challenge task and what I have done passes (I think the instructions are a little vague as it just states to call the Person constructor as though you don't need to change any more of the existing code)

Stewart Horsfield
Stewart Horsfield
13,293 Points

Thanks Emma, I ended up working out what it wanted, but you are on the money.

Because the question seemed very specific, and wasn't asking us to remove 'this.firstName = firstName', etc., I expected that to be in the following question, so it took me a little while to work out what was wrong.

Cheers.