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

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; };