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 trialMatt Bloomer
10,608 PointsCan someone help me?
Is anyone working today? Can you please help me?
function Monster(name) {
this.name = name;
this.health = 100;
Monster.prototype{
this.health--;
}
}
2 Answers
shilohpalomino
Courses Plus Student 863 PointsMonster.prototype.What? You need to name the property/method you're adding to the prototype. Most likely damage. Is that your question?
Jacob Mishkin
23,118 PointsYour code needs to look like this:
function Monster(name) {
this.name = name;
this.health = 100;
}
Monster.prototype.takeDamage = function(){
this.health--;
}
what you are doing is taking the takeDamage function out of the Monster constructor function and applying the prototype. The reason for this is so that once the constructor function is called the takeDamage function won't be called multiple times when you create objects based on the constructor function.
the same questions was asked on Treehouse earlier. I think Samuel's post is very useful.
Matt Bloomer
10,608 PointsMatt Bloomer
10,608 PointsWhen I did add a function, it said that Monster.prototype was not a function; what is the answer to this?