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

dangermin field
dangermin field
10,592 Points

Object-Oriented JavaScript Challenge 1 of 2

System will not let me pass and I'm sure that I have entered the correct code. Any help will be appreciated.

Question: 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.

Answer: function Person(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; }

Person.prototype.fullName = function() { return this.firstName + " " + this.lastName; };

function Teacher(firstName, lastName, ) { Person.call(this, firstName, lastName); }

Error code: Bummer! You're missing Person.call in the Teacher construction function.

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) {
  this.firstName = firstName;
  this.lastName = lastName;
  this.room = roomNumber;
}
dangermin field
dangermin field
10,592 Points

I've tried all variations of the answers that I've found in the community chat, nothing will pass.

5 Answers

dangermin field
dangermin field
10,592 Points

Man I've been entering the code into the person.js. Just read TEACHER TAB in the comment above a noticed me fault.

Thanks Daryl

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I know this may seem odd but to pass the first step of the challenge you have to remove the stuff already in the Teacher object. Then you use the Person.call. Put this code in your teacher.js and nothing else:

function Teacher(firstName, lastName, roomNumber) {
  Person.call(this, firstName, lastName);
  this.room = roomNumber;
}
Daryl Carr
Daryl Carr
18,318 Points

Hey its telling you to call the Person constructor in the Teacher constructor. The call method lets you apply a function changing the this. So here the this is the teacher and allows you to set the given arguments using the methods in the Person constructor. Below is the code you need;

function Teacher(firstName, lastName, roomNumber) {
  Person.call(this, firstName, lastName)
  this.room = roomNumber;
}
dangermin field
dangermin field
10,592 Points

I've tried all possible options, with and w/o the roomNumber option and nothing passes. The roomNumber argument isn't even mentioned in part 1 of the challenge so if it is the key Treehouse should fix it but the people at Treehouse say the code works on their end so....I'm stuck here with every section of the Developer Track complete but this one question.

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.room = roomNumber; }

Daryl Carr
Daryl Carr
18,318 Points

These are silly questions but who knows sometimes we missed things. Have you tried the reset code button? Then gone to the TEACHER TAB and then deleted the two lines re firstName and lastName. and posted in the code re the Person.call?

i think the reason the answer isn't passing because it's looking for the this.room = roomNumber line as well. Looks like your answer had only the Person.call line.