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

Can't figure it out

help

monster.js
function Monster (name) {
};
 var newMonster = Monster.name("Name");

3 Answers

function Person(first, last, age, eye) {
    this.firstName = first;
    this.lastName = last;
    this.age = age;
    this.eyeColor = eye;
}

^ example of a good constructor

function Monster (name) {
};

^ start your attempt from that point.

Steven Parker
Steven Parker
217,443 Points

Here's a few hints:

  • the instruction say to assign the property "Inside the constructor function"
  • the name of the property should be "name" (not "newMonster")
  • property names should be preceded by "this."
  • don't put quotes around the parameter name
Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 90,824 Points

Hi Bozin,

You want to use the .this syntax inside your constructor function.

You don't need to create a new instance of the constructor in the code challenge, all you do is set the properties of the constructor.

So...

this.name = name