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

Jack Cummins
Jack Cummins
17,417 Points

I give out best answers! If you give me a high quality answer I will give out a best answer.

Assignment: You're going to modify the Teacher code to inherit from the Person. First, in the Teacher constructor function, call the Person constructor, using the call method and pass in the common attributes.

Thanks, Jack

P.S. Don't forget about the best answer!

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

function Teacher(firstName, lastName, roomNumber) {
  Person.call(this, firstName, lastName)
  this.room = roomNumber;
}
teacher.js
function Teacher(firstName, lastName, roomNumber) {
  this.firstName = firstName;
  this.lastName = lastName;
  this.room = roomNumber;
}
Steven Parker
Steven Parker
231,269 Points

It's great that you're following forum "best practices" regarding your follow-up with best answers. :+1: But it's not necessary to mention it in a question title. It would be more helpful to put something in the title that related to the question itself.

Also, while I'm sure folks who answer appreciate getting the positive feedback, I expect that we all do it because we genuinely like to help. Anyone it matters to will know your history and won't need a reminder anyway.

Gabbie Metheny
Gabbie Metheny
33,778 Points

Agreed. I would've answered this question regardless, and it is helpful to see some relevant info in the post title, so people have an idea whether or not they'd be qualified to answer.

1 Answer

Gabbie Metheny
Gabbie Metheny
33,778 Points

Your Teacher function is exactly right, but it's in the wrong document: you need to modify the existing Teacher in teacher.js rather than adding a new one to person.js. You also deleted your Person prototype in the process, so I'd just restart the challenge to get that back, then modify the Teacher function in teacher.js to the code you currently have in person.js.

That should get you to Step 2 of the challenge, let me know if you get stuck there, or if the above suggestion doesn't work!