Skip to content

Commit 42a4388

Browse files
committed
solve stretch goal problem
1 parent 43fdda7 commit 42a4388

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

‎assignments/prototypes.js‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,60 @@ const archer = new Humanoid({
121121
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
122122
// * Give the Hero and Villains different methods that could be used to remove health points from objects which could result in destruction if health gets to 0 or drops below 0;
123123
// * Create two new objects, one a villain and one a hero and fight it out with methods!
124+
125+
// function for Villian
126+
function Villain(player) {
127+
Humanoid.call(this, player);
128+
}
129+
130+
Villain.prototype.call = Object.create(Humanoid.prototype);
131+
132+
Villain.prototype.life = function() {
133+
return this.healthPoints > 1
134+
? (this.healthPoints = this.healthPoints - 1)
135+
: this.destroy();
136+
};
137+
138+
// function for Hero
139+
function Hero(player) {
140+
Humanoid.call(this, player);
141+
}
142+
143+
Hero.prototype = Object.create(Humanoid.prototype);
144+
145+
Hero.prototype.life = function() {
146+
return this.healthPoints > 1
147+
? (this.healthPoints = this.healthPoints - 1)
148+
: this.destroy();
149+
};
150+
151+
152+
const hero = new Hero({
153+
createdAt: new Date(),
154+
dimensions: {
155+
length: 1,
156+
width: 3,
157+
height: 2
158+
},
159+
healthPoints: 6,
160+
name: "Uche",
161+
team: "The Round Table",
162+
weapons: ["Giant Sword", "Shield"],
163+
language: "Common Tongue"
164+
});
165+
166+
const villain = new Villain({
167+
createdAt: new Date(),
168+
dimensions: {
169+
length: 1,
170+
width: 3,
171+
height: 2
172+
},
173+
healthPoints: 5,
174+
name: "Mark",
175+
team: "The Round Table",
176+
weapons: ["Giant Sword", "Shield"],
177+
language: "Common Tongue"
178+
});
179+
180+
console.log(hero.life());

0 commit comments

Comments
 (0)