Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Object-Oriented JavaScript (2015) Constructor Functions and Prototypes Create a Constructor

Tiffany White
Tiffany White
5,373 Points

I am confused by the instructions here.

Not certain what this is asking: Modify the Monster constructor to take one parameter of name. Inside the constructor function, when it creates a new instance assign the parameter name to the property of name on the new instance.

monster.js
function Monster (name) {

}

2 Answers

Steven Parker
Steven Parker
218,583 Points

Remember that the new instance is referred to as this. So you want something like:

function Monster (name) {
    this.name = name;
}

This is very similar to what was done in the video using Dice and sides.

Tiffany White
Tiffany White
5,373 Points

Yeah I figured it out. Thanks for answering the question though.

Shane Oliver
Shane Oliver
19,965 Points

you need to add a property on the Monster object of name that is equal to the argument of name

this.name = name;