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 trialMateusz Hyla
11,210 PointsWhat is wring with my code [OOP JavaScript]?
Hello
I have a problem with code challange. There is said to call a constructor of Person class in Teacher constructor. I done that like :
Person.call(this , firstName , lastName);
And it shows me an error that firstName and lastName does not need to be set up there.
When I try another approach like :
Person.call("Matt","Hyla");
It said that I need to place arguments in order like : "this" , "firstName" and "lastName",
I don't know what to do now. What am I doing wrong ?
Cheers
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.fullName = function() {
return this.firstName + " " + this.lastName;
};
function Teacher(firstName, lastName, roomNumber) {
this.firstName = firstName;
this.lastName = lastName;
this.room = roomNumber;
}
1 Answer
Steven Parker
231,269 PointsYou had the right idea the first time.
You probably just forgot to remove the redundant lines from the Teacher constructor:
function Teacher(firstName, lastName, roomNumber) {
Person.call(this, firstName, lastName); // this sets up both names, we don't need to here
this.room = roomNumber; // but we still assign the room
}