You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit bb4d64d
Browse filesBrowse the repository at this point in the historyBrowse files
// Test you work by un-commenting these 3 objects and the list of console logs below:
43
85
44
-
/*
86
+
45
87
constmage=newHumanoid({
46
88
createdAt: newDate(),
47
89
dimensions: {
@@ -102,9 +144,109 @@
102
144
console.log(archer.greet());// Lilith offers a greeting in Elvish.
103
145
console.log(mage.takeDamage());// Bruce took damage.
104
146
console.log(swordsman.destroy());// Sir Mustachio was removed from the game.
105
-
*/
147
+
106
148
107
149
// Stretch task:
108
150
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
109
151
// * 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;
110
-
// * Create two new objects, one a villain and one a hero and fight it out with methods!
152
+
// * Create two new objects, one a villain and one a hero and fight it out with methods!
153
+
154
+
155
+
//Hero boi
156
+
constHero=function(attributes){
157
+
Humanoid.call(this,attributes);
158
+
}
159
+
160
+
Hero.prototype=Object.create(Humanoid.prototype);
161
+
Hero.prototype.attack=function(target){
162
+
if(this.healthPoints>0){
163
+
if(target.healthPoints>0){
164
+
letdamage=(Math.round(Math.random()*10));
165
+
target.healthPoints=target.healthPoints-damage;
166
+
if(target.healthPoints>0){
167
+
console.log(`${this.name} attacked ${target.name} for ${damage} points! ${target.name} now has ${target.healthPoints} health`)
168
+
}else{
169
+
console.log(`${this.name} attacked ${target.name} for ${damage} points and destroyed ${target.name}!`)
170
+
}
171
+
}else{
172
+
console.log(`${this.name} kicked ${target.name}'s dead body`)
0 commit comments