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

I don't understand what it's asking me to do here. Everything I've tried doesn't work.

Do i need a var?

monster.js
function Monster() {

} 

2 Answers

cm21
cm21
150,854 Points

Hi Melissa,

For task 1, your code passes on my end, though you could also try it this way:

Monster = function() {

}

For task 2, you need to give the constructor a parameter of name, so you'll put that within the parentheses. This constructor creates a new instance of Monster, and the challenge asks us to assign the parameter name (which we named 'name') to this instance's name property. The 'this' keyword represents the instance within the constructor code, and the '.property' syntax is used to represent the property.

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

For task 3, you will be adding a numerical value of 100 to the health property for the new instance. Remembering that the 'this' keyword represents the new instance, and that we use the '.property' syntax to represent the property, we will write this code as 'this.health = 100;'.

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

Hope this helps!

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,627 Points

Hi Melissa, You are really close, you just have it backwards.

Monster = function() {

}

Keep Coding! :)