Skip to content

Commit 38ea645

Browse files
Jashele TJashele T
authored andcommitted
fixed undefined
1 parent 92c5612 commit 38ea645

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

assignments/prototypes.js

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ function GameObject(GameObj) {
2525

2626
this.dimensions = GameObj.dimensions; // (These represent the character's size in the video game)
2727

28-
GameObj.prototype.destroy = function(destroyFunc) {
29-
return `${this.name} was removed from the game.`; // prototype method that returns: `${this.name} was removed from the game.`
3028

3129
};
30+
31+
GameObject.prototype.destroy = function() {
32+
return `${this.name} was removed from the game.`; // prototype method that returns: `${this.name} was removed from the game.`
33+
34+
3235
}
3336

3437

@@ -38,16 +41,30 @@ function GameObject(GameObj) {
3841

3942
// === CharacterStats ===
4043

41-
function CharacterStats(CharStats) {
4244

43-
this.healthPoints = CharStats.healthPoints;
45+
function CharacterStats(charAttrs) {
46+
GameObject.call(this, charAttrs);
47+
this.healthPoints = charAttrs.healthPoints;
48+
};
4449

45-
CharacterStats.prototype.takeDamage = function() {
46-
return `${this.name} took damage.`; // prototype method -> returns the string '<object name> took damage.'
47-
}
50+
CharacterStats.prototype = Object.create(GameObject.prototype);
4851

49-
CharacterStats.prototype = Object.create(GameObject.prototype); // should inherit destroy() from GameObject's prototype
50-
};
52+
CharacterStats.prototype.takeDamage = function () {
53+
return `${this.name} took damage`;
54+
}
55+
56+
// function CharacterStats(CharStats) {
57+
// CharacterStats.prototype = Object.create(GameObject.prototype);
58+
// this.healthPoints = CharStats.healthPoints;
59+
60+
61+
62+
// // should inherit destroy() from GameObject's prototype
63+
// };
64+
65+
// CharacterStats.prototype.takeDamage = function() {
66+
// return `${this.name} took damage.`; // prototype method -> returns the string '<object name> took damage.'
67+
// }
5168

5269

5370

@@ -57,27 +74,33 @@ function GameObject(GameObj) {
5774
// === Humanoid (Having an appearance or character resembling that of a human.) ===
5875

5976
function Humanoid(HumanoidAttr) {
60-
77+
CharacterStats.call(this, HumanoidAttr);
6178
this.team = HumanoidAttr.team;
6279

6380
this.weapons = HumanoidAttr.weapons;
6481

6582
this.language = HumanoidAttr.language;
6683

67-
Humanoid.prototype.greet = function(greeting) {
68-
return `${this.name} offers a greeting in ${this.language}.`
69-
// prototype method -> returns the string '<object name> offers a greeting in <object language>.'
84+
};
85+
7086

71-
Humanoid.prototype = Object.create(CharacterStats.prototype); // should inherit destroy() from GameObject through CharacterStats
7287

73-
CharacterStats.prototype = Object.create(CharacterStats.prototype);
88+
Humanoid.prototype = Object.create(CharacterStats.prototype);
7489
// should inherit takeDamage() from CharacterStats
75-
};
90+
91+
92+
93+
Humanoid.prototype.greet = function() {
94+
return `${this.name} offers a greeting in ${this.language}.`
95+
// prototype method -> returns the string '<object name> offers a greeting in <object language>.'
96+
7697

7798
}
7899

100+
101+
102+
79103

80-
81104

82105

83106

0 commit comments

Comments
 (0)