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

Object-Orientated JS Challenge Task 1 of 2 PLEASE help

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.

I've tried several different ways and can't seem to get it.

person.js
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; 
}
teacher.js
function Teacher(firstName, lastName, roomNumber) {
  this.firstName = firstName;
  this.lastName = lastName;
  this.room = roomNumber;
}

4 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Madisyn,

I'm sorry it's taken so long for you question to be addressed.

The first part of the challenge wants you to .call the Person constructor in the Teacher constructor like so

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

Once you use Person.call you no longer need the two lines that I've deleted, because the Person constructor will no be taking care of those lines in its code. Make sense?

For the second part of the challenge, you just have to add the line of code so that the Teacher can "inherit" from the Person.

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

Teacher.prototype = Object.create(Person.prototype);

I'm not sure I can really explain this part well. It's basically allowing the Teacher to use the Person. Andrew explains it in the previous video (the one before the challenge) at about 2:30.

Hope this makes sense and helps. Keep Coding! :)

Saad Khan Malik
Saad Khan Malik
25,199 Points
function Teacher(firstName, lastName, roomNumber) {
  Person.call(this, firstName, lastName);
  this.room = roomNumber;
}// missed this bracket :)
Teacher.prototype = Object.create(Person.prototype);
Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Good catch Saad Malik :)

Answer has been fixed to include the originally missing closing brace. Thank you ;)

Ben Ahlander
Ben Ahlander
7,528 Points

Okay, so Teacher and Person are capitalized because its referring to the constructor functions, not the name of the files? but why does "Object" need to be capitalized?

Charles Diamond
Charles Diamond
6,069 Points

i had the code in the wrong file. I put the answer in teacher.js, not person.js and I passed.

Okay...I'm using the EXACT same code you provided for step one. I'm getting a "Bummer you're missing the "Person.call"' in your code?...but I'm not! What the heck?

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Hey Edward,

There are two tabs when the challenge opens. The person.js and the teacher.js tab.

The code must be pasted in the teacher.js tab. The person.js tab does not get altered at all for this challenge.

:)

Juliette Tworsey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 Points

The same thing happens to me on challenges from time to time....I'll have the exact same code it doesn't pass, then when I copy/paste it does. It's a glitch apparently..

Jessica Jimenez Hageman
Jessica Jimenez Hageman
7,670 Points

Thank you @Jason! Maybe it should be rephrased to alter the Teacher.js code.