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

Mohammed Ali
Mohammed Ali
10,625 Points

Hi, I'm stuck on Object-Oriented JavaScript, Setting up the Prototype Chain. Can someone give a hand please?

In teacher.js -

Solution: Person.call(this, firstName, lastName); Error message: Bummer! You don't need to set the firstName or lastName properties, the Person.call will handle that!

Solution: Person.call(this); Error: Bummer! The Person.call method needs this, firstName and lastName, in that order!

Any advice would be super useful. Thanks

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

Raja Kannan
Raja Kannan
6,590 Points

Hi Mohammed Ali, You are almost correct. You had inherited the code form Person. So no need to repeat firstname and lastname after Person.call method. Because these two properties are defined in Person which we are inheriting.

this.firstName = firstName;
this.lastName = lastName; 

try the code below:

function Teacher(firstName, lastName, roomNumber) {
  Person.call(this,firstName, lastName);
  this.room = roomNumber;
}
Mohammed Ali
Mohammed Ali
10,625 Points

That worked, thanks Raja

This is not an answer rather a question. The challenge has a Step 2. This is my solution:

function Teacher(firstName, lastName, roomNumber) { Person.call(this, firstName, lastName); this.room = roomNumber; } Teacher.prototype = Object.create(Person.prototye);

For some reason I receive this msg again and again: Bummer! You have an assignment but not Teacher.prototype = Object.create(); with the Person's prototype.

??? pls help