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

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
229,644 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 91,252 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