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 trial

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

Chase Marchione
Chase Marchione
155,055 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,858 Points

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

Monster = function() {

}

Keep Coding! :)