Skip to content

Commit 2f38956

Browse files
committed
prototypes complete, mvp complete
1 parent 413a1ce commit 2f38956

2 files changed

Lines changed: 50 additions & 17 deletions

File tree

assignments/prototypes.js

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
Each constructor function has unique properties and methods that are defined in their block comments below:
99
*/
10-
10+
1111
/*
1212
=== GameObject ===
1313
* createdAt
@@ -16,12 +16,32 @@
1616
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
1717
*/
1818

19+
function GameObject(attributes) {
20+
this.createdAt = attributes.createdAt;
21+
this.name = attributes.name;
22+
this.dimensions = attributes.dimensions;
23+
}
24+
25+
GameObject.prototype.destroy = function() {
26+
return `${this.name} was removed from the game.`;
27+
};
28+
1929
/*
2030
=== CharacterStats ===
2131
* healthPoints
2232
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
2333
* should inherit destroy() from GameObject's prototype
2434
*/
35+
function CharacterStats(attributes) {
36+
GameObject.call(this, attributes);
37+
this.healthPoints = attributes.healthPoints;
38+
}
39+
CharacterStats.prototype = Object.create(GameObject.prototype);
40+
41+
CharacterStats.prototype.takeDamage = function() {
42+
return `${this.name} took damage.`;
43+
};
44+
2545

2646
/*
2747
=== Humanoid (Having an appearance or character resembling that of a human.) ===
@@ -32,16 +52,29 @@
3252
* should inherit destroy() from GameObject through CharacterStats
3353
* should inherit takeDamage() from CharacterStats
3454
*/
35-
55+
56+
function Humanoid(attributes) {
57+
CharacterStats.call(this, attributes);
58+
this.team = attributes.team;
59+
this.weapons = attributes.weapons;
60+
this.language = attributes.language;
61+
}
62+
Humanoid.prototype = Object.create(CharacterStats.prototype);
63+
64+
Humanoid.prototype.greet = function() {
65+
return `${this.name} offers a greeting in ${this.language}`;
66+
};
67+
68+
3669
/*
37-
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
38-
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
39-
* Instances of CharacterStats should have all of the same properties as GameObject.
40-
*/
70+
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
71+
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
72+
* Instances of CharacterStats should have all of the same properties as GameObject.
73+
*/
4174

4275
// Test you work by un-commenting these 3 objects and the list of console logs below:
4376

44-
/*
77+
4578
const mage = new Humanoid({
4679
createdAt: new Date(),
4780
dimensions: {
@@ -102,9 +135,9 @@
102135
console.log(archer.greet()); // Lilith offers a greeting in Elvish.
103136
console.log(mage.takeDamage()); // Bruce took damage.
104137
console.log(swordsman.destroy()); // Sir Mustachio was removed from the game.
105-
*/
106138

107-
// Stretch task:
108-
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
109-
// * 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!
139+
140+
// Stretch task:
141+
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
142+
// * 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;
143+
// * Create two new objects, one a villain and one a hero and fight it out with methods!

assignments/this.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
// Principle 1
1313

14-
// function myName(name) {
15-
// console.log(this);
16-
// return name;
17-
// }
18-
// myName('Jose');
14+
function myName(name) {
15+
console.log(this);
16+
return name;
17+
}
18+
myName('Jose');
1919

2020
// Principle 2
2121

0 commit comments

Comments
 (0)