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

Finally, Monsters have a health property. When they take damage from the player, their health will reduce. All new Monst

Finally, Monsters have a health property. When they take damage from the player, their health will reduce. All new Monster instances should have 100 health by default. It should be a number not a string. I have this code . doesnt work too well

monster.js
function Monster (name, health){
  this.name=name;
  this.health= function(){
    var h =100*damage;
    var damage;
  };

}

8 Answers

Just went through it my self. It is just this.health = 100; I was going as far as a function and I was incorrect. so just shorten it down to the above.

MOD note: Change from comment to answer. Can now be up-voted or marked as best answer.

found out : function Monster (name, health){ this.name=name; this.health= 100; this.takeDamage = function (){ this.health--; } ; }

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

A semicolon isn't needed at the final }.

Here you go...

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

george NGOWI
PLUS
george NGOWI
Courses Plus Student 7,499 Points

This works for me: function Monster (name, health) { this.name=name; this.health= 100; this.Damage = function (){ this.Damage = this.health-- ; } }

to pass the test you need to put health as second parameter and put it as this.health = 100;

I was able to pass by using, function Monster(name) { this.name=name; this.health=parseInt(100); }

Amany Oweja
Amany Oweja
4,018 Points

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