Skip to content

Commit 5328647

Browse files
authored
Merge pull request #1 from jasheloper/jashele-tillman
Good Job
2 parents 300f003 + 12c2207 commit 5328647

File tree

2 files changed

+275
-0
lines changed

2 files changed

+275
-0
lines changed

assignments/lambda-classes.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,82 @@
11
// CODE here for your Lambda Classes
2+
3+
class Person {
4+
constructor(attributes) {
5+
this.name = attributes.name;
6+
this.age = attributes.age;
7+
this.location = attributes.location;
8+
}
9+
10+
speak() {
11+
return `Hello, my name is ${this.name}, I am from ${this.location}.`
12+
}
13+
}
14+
15+
class Instructor extends Person {
16+
constructor(attributes) {
17+
super(attributes);
18+
this.specialty = attributes.specialty;
19+
this.favLanguage = attributes.favLanguage;
20+
this.catchPhrase = attributes.catchPhrase;
21+
}
22+
23+
demo() {
24+
const subject = 'JavaScript';
25+
return `Today we are learning about ${this.subject}.`
26+
}
27+
28+
grade() {
29+
const studentname = 'Jashele Tillman';
30+
return `${this.studentname} receives a perfect score on ${this.subject}.`
31+
}
32+
}
33+
34+
35+
class Student extends Person {
36+
constructor(attributes) {
37+
super(attributes);
38+
this.previousbackground = attributes.previousbackground;
39+
this.className = attributes.className;
40+
this.favSubjects = attributes.favSubjects;
41+
}
42+
43+
listsSubjects() {
44+
return `${this.favSubjects}`;
45+
}
46+
47+
PRAssignments() {
48+
return `${this.studentname} has submitted a PR for ${this.subject}.`
49+
}
50+
51+
sprintChallenge() {
52+
return `${this.studentname} has begun sprint challenge on ${this.subject}.`
53+
}
54+
55+
}
56+
57+
class ProjectManager extends Person {
58+
constructor(attributes) {
59+
super(attributes);
60+
this.gradClassName = attributes.gradClassName;
61+
this.favInstructor = attributes.favInstructor;
62+
}
63+
64+
standUp(channel) {
65+
return `${this.name} announces to ${channel}, @channel standby times!`;
66+
}
67+
debugsCode() {
68+
return `${this.name} debugs ${this.studentname} code on ${this.subject}.`;
69+
}
70+
}
71+
72+
const Jashele = new Student ({
73+
name: 'Jashele',
74+
age: 100,
75+
location: 'Earth',
76+
previousbackground: 'Panda',
77+
className: 'Web PT 7',
78+
favSubjects: ['User Interface']
79+
})
80+
81+
console.log(Jashele);
82+

assignments/prototype-refactor.js

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,197 @@ Prototype Refactor
77
2. Your goal is to refactor all of this code to use ES6 Classes. The console.log() statements should still return what is expected of them.
88
99
*/
10+
11+
12+
13+
14+
/*
15+
Object oriented design is commonly used in video games. For this part of the assignment you will be implementing several constructor functions with their correct inheritance hierarchy.
16+
17+
In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid.
18+
19+
At the bottom of this file are 3 objects that all end up inheriting from Humanoid. Use the objects at the bottom of the page to test your constructor functions.
20+
21+
Each constructor function has unique properties and methods that are defined in their block comments below:
22+
*/
23+
24+
25+
// Notes:
26+
// GameObject -> CharacterStats -> Humanoid
27+
28+
29+
30+
31+
// === GameObject ===
32+
33+
// function GameObject(GameObj) {
34+
// this.createdAt = GameObj.createdAt;
35+
// this.name = GameObj.name;
36+
// this.dimensions = GameObj.dimensions; // (These represent the character's size in the video game)
37+
// };
38+
39+
40+
// GameObject Object Refactored:
41+
42+
class GameObject {
43+
constructor(GameObj){
44+
this.createdAt = GameObj.createdAt;
45+
this.name = GameObj.name;
46+
this.dimensions = GameObj.dimensions;
47+
}
48+
49+
50+
51+
// GameObject.prototype.destroy = function() {
52+
// return `${this.name} was removed from the game.`; // prototype method that returns: `${this.name} was removed from the game.`
53+
// }
54+
55+
56+
57+
// Prototype Refactored:
58+
destroy() {
59+
return `${this.name} was removed from the game.`;
60+
}
61+
}
62+
63+
64+
65+
66+
// === CharacterStats ===
67+
68+
// function CharacterStats(charAttrs) {
69+
// GameObject.call(this, charAttrs);
70+
// this.healthPoints = charAttrs.healthPoints;
71+
// };
72+
73+
74+
75+
// CharacterStats Refactored:
76+
77+
class CharacterStats extends GameObject {
78+
constructor(charAttrs){
79+
super(charAttrs);
80+
this.healthPoints = charAttrs.healthPoints;
81+
}
82+
83+
84+
85+
// CharacterStats.prototype = Object.create(GameObject.prototype);
86+
87+
// CharacterStats.prototype.takeDamage = function () {
88+
// return `${this.name} took damage`;
89+
// }
90+
91+
92+
93+
// CharacterStats Prototype Refactored:
94+
95+
takeDamage(){
96+
return `${this.name} took damage`;
97+
}
98+
}
99+
100+
101+
102+
103+
104+
// === Humanoid (Having an appearance or character resembling that of a human.) ===
105+
106+
// function Humanoid(HumanoidAttr) {
107+
// CharacterStats.call(this, HumanoidAttr);
108+
// this.team = HumanoidAttr.team;
109+
// this.weapons = HumanoidAttr.weapons;
110+
// this.language = HumanoidAttr.language;
111+
// };
112+
113+
114+
115+
// Humanoid Refactored:
116+
117+
class Humanoid extends CharacterStats {
118+
constructor(HumanoidAttr) {
119+
super(HumanoidAttr);
120+
this.team = HumanoidAttr.team;
121+
this.weapons = HumanoidAttr.weapons;
122+
this.language = HumanoidAttr.language;
123+
}
124+
125+
126+
// Humanoid.prototype = Object.create(CharacterStats.prototype);
127+
// should inherit takeDamage() from CharacterStats
128+
129+
130+
// Humanoid.prototype.greet = function() {
131+
// return `${this.name} offers a greeting in ${this.language}.`
132+
// // prototype method -> returns the string '<object name> offers a greeting in <object language>.'
133+
// }
134+
135+
// Humanoid Prototype Refactor:
136+
137+
greet(){
138+
return `${this.name} offers a greeting in ${this.language}.`
139+
}
140+
}
141+
142+
143+
144+
/*
145+
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
146+
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
147+
* Instances of CharacterStats should have all of the same properties as GameObject.
148+
*/
149+
150+
// Test you work by un-commenting these 3 objects and the list of console logs below:
151+
152+
153+
154+
const mage = new Humanoid({
155+
createdAt: new Date(),
156+
dimensions: {length: 2, width: 1, height: 1, },
157+
healthPoints: 5,
158+
name: 'Bruce',
159+
team: 'Mage Guild',
160+
weapons: ['Staff of Shamalama',],
161+
language: 'Common Tongue',
162+
});
163+
164+
165+
166+
const swordsman = new Humanoid({
167+
createdAt: new Date(),
168+
dimensions: {length: 2, width: 2, height: 2, },
169+
healthPoints: 15,
170+
name: 'Sir Mustachio',
171+
team: 'The Round Table',
172+
weapons: ['Giant Sword', 'Shield',],
173+
language: 'Common Tongue',
174+
});
175+
176+
177+
const archer = new Humanoid({
178+
createdAt: new Date(),
179+
dimensions: {length: 1, width: 2, height: 4, },
180+
healthPoints: 10,
181+
name: 'Lilith',
182+
team: 'Forest Kingdom',
183+
weapons: ['Bow', 'Dagger', ],
184+
language: 'Elvish',
185+
});
186+
187+
188+
console.log(mage.createdAt); // Today's date
189+
console.log(archer.dimensions); // { length: 1, width: 2, height: 4 }
190+
console.log(swordsman.healthPoints); // 15
191+
console.log(mage.name); // Bruce
192+
console.log(swordsman.team); // The Round Table
193+
console.log(mage.weapons); // Staff of Shamalama
194+
console.log(archer.language); // Elvish
195+
console.log(archer.greet()); // Lilith offers a greeting in Elvish.
196+
console.log(mage.takeDamage()); // Bruce took damage.
197+
console.log(swordsman.destroy()); // Sir Mustachio was removed from the game.
198+
199+
200+
// Stretch task:
201+
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
202+
// * 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;
203+
// * Create two new objects, one a villain and one a hero and fight it out with methods!

0 commit comments

Comments
 (0)