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 trialjohn larson
16,594 PointsI'm drawing a blank on this prototype question
function Monster(rank) {
this.rank = rank;
this.health = 100;
}
Monster._______.takeHit = function() {
this.health--;
}
I tried "this.health" and "health". Both are incorrect, so idk.
john larson
16,594 PointsThank you Mark, I did prototypes on w3s, I don't remember them using .prototype syntax. Is this a long hand version of another syntax?
Kevin Faust
15,353 Pointsscroll to the very bottom of w3s javascript prototypes and you will find it. its the most standard and common way to creating prototypes
john larson
16,594 PointsThanks kevin, I will take another look at w3s, I must have missed it.
1 Answer
Kevin Faust
15,353 Pointsits "prototype" ^^ because all monsters should be able to be hit
john larson
16,594 PointsThank you kevin. Out of three questions "prototype" was the answer to two of them. "because all monsters should be able to be hit it", makes perfect sense.
Mark Miller
45,831 PointsMark Miller
45,831 PointsThis is a prototype function. Every time you create a "new" Monster, it should be able to invoke this takeHit function. The special word prototype is used in the dot notation here in between Monster and takeHit, so that any object of the Monster type will be able to use this takeHit function. So this declaration needs the word prototype included.