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 trialMark Mueller
20,238 PointsOOJS Prototypal Inheritance Code Challenge Question 1
I am wondering if the challenge itself if broken. I input my code and I am returned an error " Bummer! You don't need to set the firstName or lastName properties, the Person.call will handle that!" If I take all the properties out I get this error " Bummer! The Person.call
method needs this
, firstName
and lastName
, in that order!".
This code challenge is giving me mixed signals!
HELP!
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.firstName = firstName;
this.lastName = lastName;
this.room = roomNumber;
}
Teacher.prototype = Object.create(Person.prototype);
1 Answer
Eric Moody
12,373 PointsGood work so far, but the challenge is asking you to remove the redundant code.
function Teacher(firstName, lastName, roomNumber) { Person.call(this, firstName, lastName); this.firstName = firstName; this.lastName = lastName; this.room = roomNumber; }
Your function is calling the this.firstName = firstName and the this.lastName = lastName from the person function already when you included the Person.call(this, firstName, lastName);
Just delete the this.first and this.last in order to make it pass. Like this.
function Teacher(firstName, lastName, roomNumber) { Person.call(this, firstName, lastName); this.room = roomNumber; }
Happy coding!
Mark Mueller
20,238 PointsMark Mueller
20,238 PointsOf course!
I was so caught up in why it wasn't working that I forgot to DRY.