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 trialMadisyn Haarman
3,832 PointsObject-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.
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;
}
function Teacher(firstName, lastName, roomNumber) {
this.firstName = firstName;
this.lastName = lastName;
this.room = roomNumber;
}
4 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHi 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! :)
Charles Diamond
6,069 Pointsi had the code in the wrong file. I put the answer in teacher.js, not person.js and I passed.
Edward Stieren
5,997 PointsOkay...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
Treehouse Moderator 145,860 PointsHey 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
Front End Web Development Techdegree Graduate 32,425 PointsThe 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
7,670 PointsThank you @Jason! Maybe it should be rephrased to alter the Teacher.js code.
Saad Khan Malik
25,199 PointsSaad Khan Malik
25,199 PointsJason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsGood catch Saad Malik :)
Answer has been fixed to include the originally missing closing brace. Thank you ;)
Ben Ahlander
7,528 PointsBen Ahlander
7,528 PointsOkay, 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?