Skip to content

Commit e5cbb1b

Browse files
prototypes.js completed
1 parent 566fc04 commit e5cbb1b

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

‎assignments/prototypes.js‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,43 @@
3939
* Instances of CharacterStats should have all of the same properties as GameObject.
4040
*/
4141

42+
function GameObject (objAttributes) {
43+
this.createdAt = objAttributes.createdAt;
44+
this.dimensions = objAttributes.dimensions;
45+
}
46+
47+
GameObject.prototype.destroy = function (){
48+
return `${this.name} was removed from the game.`;
49+
}
50+
51+
function CharacterStats(charAttributes){
52+
GameObject.call(this, charAttributes);
53+
this.hp = charAttributes.hp;
54+
this.name = charAttributes.name;
55+
}
56+
57+
CharacterStats.prototype = Object.create(GameObject.prototype);
58+
59+
CharacterStats.prototype.takeDamage = function (){
60+
return `${this.name} took damage`;
61+
};
62+
63+
function Humanoid(humanAttributes){
64+
CharacterStats.call(this, humanAttributes);
65+
this.faction = humanAttributes.faction;
66+
this.weapons = humanAttributes.weapons;
67+
this.language = humanAttributes.language;
68+
}
69+
70+
Humanoid.prototype = Object.create(CharacterStats.prototype);
71+
72+
Humanoid.prototype.greet = function (){
73+
return `${this.name} offers a greeting in ${this.language}`;
74+
}
75+
4276
// Test you work by uncommenting these 3 objects and the list of console logs below:
4377

44-
/*
78+
4579
const mage = new Humanoid({
4680
createdAt: new Date(),
4781
dimensions: {
@@ -102,7 +136,6 @@
102136
console.log(archer.greet()); // Lilith offers a greeting in Elvish.
103137
console.log(mage.takeDamage()); // Bruce took damage.
104138
console.log(swordsman.destroy()); // Sir Mustachio was removed from the game.
105-
*/
106139

107140
// Stretch task:
108141
// * Create Villian and Hero constructor functions that inherit from the Humanoid constructor function.

0 commit comments

Comments
 (0)