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 trialeli d
Courses Plus Student 2,510 PointsFinally, 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
function Monster (name, health){
this.name=name;
this.health= function(){
var h =100*damage;
var damage;
};
}
8 Answers
andrew schoenherr
8,427 PointsJust 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.
eli d
Courses Plus Student 2,510 Pointsfound out : function Monster (name, health){ this.name=name; this.health= 100; this.takeDamage = function (){ this.health--; } ; }
Mike Siwik
Front End Web Development Techdegree Student 14,814 Pointsfunction Monster(name) {
this.name=name;
this.health=100;
}
A semicolon isn't needed at the final }.
Chris Himes
8,043 PointsHere you go...
function Monster (name, health) { this.name=name; this.health= 100; this.takeDamage = function (){ this.takeDamage = this.health - health ; } ; }
george NGOWI
Courses Plus Student 7,499 PointsThis works for me: function Monster (name, health) { this.name=name; this.health= 100; this.Damage = function (){ this.Damage = this.health-- ; } }
gagan singh
Full Stack JavaScript Techdegree Student 12,889 Pointsto pass the test you need to put health as second parameter and put it as this.health = 100;
Bill Timber
3,463 PointsI was able to pass by using, function Monster(name) { this.name=name; this.health=parseInt(100); }
Amany Oweja
4,018 Pointsthis is the solution function Monster(name){ this.name=name; this.health=100; };