Skip to content

Commit 5994140

Browse files
committed
JS-IV completion
1 parent 807fd68 commit 5994140

3 files changed

Lines changed: 289 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This challenge focuses on classes in JavaScript using the new `class` keyword.
44

55
## Assignment Description
66

7-
//You already pretty much know all about classes but you're used to seeing them built in the following context:
7+
You already pretty much know all about classes but you're used to seeing them built in the following context:
88

99
```js
1010
function Person(personAttributes) {

‎assignments/lambda-classes.js‎

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,153 @@
11
// CODE here for your Lambda Classes
2+
//Person class
3+
class Person{
4+
constructor(props){
5+
this.name = props.name;
6+
this.age = props.age;
7+
this.location = props.location;
8+
this.gender = props.gender;
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(props){
17+
super(props);
18+
this.specialty = props.specialty;
19+
this.favLanguage = props.favLanguage;
20+
this.catchPhrase = props.catchPhrase;
21+
}
22+
demo(subject){
23+
return `Today we are learning about ${subject}`;
24+
}
25+
grade(student, subject){
26+
return `${student.name} receives a perfect score on ${subject}`;
27+
}
28+
}
29+
30+
class Student extends Person{
31+
constructor(props){
32+
super(props);
33+
this.previousBackground = props.previousBackground;
34+
this.className = props.className;
35+
this.favSubjects = props.favSubjects;
36+
}
37+
listsSubjects(){
38+
for(let i = 0; i < this.favSubjects.length; i++){console.log(this.favSubjects[i]);}
39+
}
40+
PRAssignment(sub){
41+
return `${this.name} has submitted a PR for ${sub}.`
42+
}
43+
sprintChallenge(sub){
44+
return `${this.name} has begun sprint challenge on ${sub};`
45+
}
46+
}
47+
48+
class ProjectManagers extends Instructor{
49+
constructor(props){
50+
super(props);
51+
this.gradClassName = props.gradClassName;
52+
this.favInstructor = props.favInstructor;
53+
}
54+
standUp(chan){
55+
return `${this.name} announces to ${chan}, @channel standy times!`;
56+
}
57+
debugsCode(student, subject){
58+
return `${this.name} debugs ${student}'s code on ${subject}`;
59+
}
60+
}
61+
62+
const Ryan = new Person({
63+
name: 'Ryan',
64+
location: 'Atlanta',
65+
age: 33,
66+
gender: 'male',
67+
});
68+
const Jones = new Person({
69+
name: 'Jones',
70+
location: 'Atlanta',
71+
age: 29,
72+
gender: 'male',
73+
});
74+
const Quinn = new Instructor ({
75+
name: 'Quinn',
76+
location: 'Atlanta',
77+
age: 33,
78+
gender: 'male',
79+
specialty: 'Defense',
80+
favLanguage: 'python',
81+
catchPhrase: 'defense almost wins championships...fn patriots'
82+
});
83+
const Manuel = new Instructor ({
84+
name: 'Manuel',
85+
location: 'Atlanta',
86+
age: 39,
87+
gender: 'male',
88+
specialty: 'Defense',
89+
favLanguage: 'javascript',
90+
catchPhrase: 'dont come in this danger zone half-steppin'
91+
});
92+
const Freeman = new Student ({
93+
name: 'Freeman',
94+
location: 'Atlanta',
95+
age: 26,
96+
gender: 'male',
97+
specialty: 'runnin that rock',
98+
favLanguage: '.Net',
99+
catchPhrase: 'just give me the ball and watch me work',
100+
previousBackground: 'worked at a funeral home',
101+
className: 'webpt4',
102+
favSubjects: ['mobile', 'networking', 'linux',]
103+
});
104+
const Sanu = new Student ({
105+
name: 'Sanu',
106+
location: 'Atlanta',
107+
age: 29,
108+
gender: 'male',
109+
specialty: 'going to get it',
110+
favLanguage: 'C',
111+
catchPhrase: 'im just gonna go get it, stop me',
112+
previousBackground: 'orange and black pack',
113+
className: 'webpt4',
114+
favSubjects: ['hardware', 'arduino', 'raspberry pi',]
115+
});
116+
const Neal = new ProjectManagers ({
117+
name: 'Neal',
118+
location: 'Atlanta',
119+
age: 23,
120+
gender: 'male',
121+
specialty: 'making people feel it in the worst way',
122+
favLanguage: 'Java',
123+
catchPhrase: "everytime you see me it'll be from your back",
124+
previousBackground: 'the swamp land',
125+
className: 'webpt4',
126+
favSubjects: ['ruby', 'sql', 'networking',],
127+
gradClassName: 'Gators',
128+
favInstructor: 'Quinn'
129+
});
130+
const DJones = new ProjectManagers ({
131+
name: 'DJones',
132+
location: 'Atlanta',
133+
age: 24,
134+
gender: 'male',
135+
specialty: 'all things lb',
136+
favLanguage: 'Android',
137+
catchPhrase: "fillin holes and strikin fear in nick foles",
138+
previousBackground: 'tiger country',
139+
className: 'webpt4',
140+
favSubjects: ['html', 'css', 'react',],
141+
gradClassName: 'Tigers',
142+
favInstructor: 'Quinn'
143+
});
144+
console.log(Ryan);
145+
console.log(Jones.speak());
146+
console.log(Quinn.catchPhrase);
147+
console.log(Manuel.speak());
148+
console.log(Freeman.listsSubjects());
149+
console.log(Sanu.PRAssignment('JS-IV'));
150+
console.log(Neal.catchPhrase);
151+
console.log(DJones.debugsCode(Sanu.name, 'JS-IV'));
152+
153+

‎assignments/prototype-refactor.js‎

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,139 @@ 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+
=== GameObject ===
13+
* createdAt
14+
* dimensions (These represent the character's size in the video game)
15+
* destroy() // prototype method -> returns the string: 'Object was removed from the game.'
16+
*/
17+
18+
19+
class GameObject{
20+
constructor(attributes){
21+
this.createdAt = attributes.createdAt;
22+
this.dimensions = attributes.dimensions;
23+
}
24+
25+
destroy(){
26+
return `Object was removed from the game.`;
27+
}
28+
}
29+
30+
31+
32+
/*
33+
=== CharacterStats ===
34+
* healthPoints
35+
* name
36+
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
37+
* should inherit destroy() from GameObject's prototype
38+
*/
39+
40+
41+
class CharacterStats extends GameObject{
42+
//GameObject.call(this, characterbutes);
43+
constructor(attributes){
44+
super(attributes);
45+
this.healthPoints = attributes.healthPoints;
46+
this.name = attributes.name;
47+
}
48+
takeDamage(){
49+
return `${this.name} took damage.`;
50+
}
51+
}
52+
53+
/*
54+
=== Humanoid (Having an appearance or character resembling that of a human.) ===
55+
* team
56+
* weapons
57+
* language
58+
* greet() // prototype method -> returns the string '<object name> offers a greeting in <object language>.'
59+
* should inherit destroy() from GameObject through CharacterStats
60+
* should inherit takeDamage() from CharacterStats
61+
*/
62+
63+
class Humanoid extends CharacterStats{
64+
constructor(attributes){
65+
super(attributes);
66+
this.team = attributes.team;
67+
this.weapons = attributes.weapons;
68+
this.language = attributes.language;
69+
}
70+
71+
great(){
72+
return `${this.team} says hello in ${this.language}`;
73+
}
74+
}
75+
76+
/*
77+
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
78+
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
79+
* Instances of CharacterStats should have all of the same properties as GameObject.
80+
*/
81+
82+
// Test you work by un-commenting these 3 objects and the list of console logs below:
83+
84+
85+
const mage = new Humanoid({
86+
createdAt: new Date(),
87+
dimensions: {
88+
length: 2,
89+
width: 1,
90+
height: 1,
91+
},
92+
healthPoints: 5,
93+
name: 'Bruce',
94+
team: 'Mage Guild',
95+
weapons: [
96+
'Staff of Shamalama',
97+
],
98+
language: 'Common Tongue',
99+
});
100+
101+
const swordsman = new Humanoid({
102+
createdAt: new Date(),
103+
dimensions: {
104+
length: 2,
105+
width: 2,
106+
height: 2,
107+
},
108+
healthPoints: 15,
109+
name: 'Sir Mustachio',
110+
team: 'The Round Table',
111+
weapons: [
112+
'Giant Sword',
113+
'Shield',
114+
],
115+
language: 'Common Tongue',
116+
});
117+
118+
const archer = new Humanoid({
119+
createdAt: new Date(),
120+
dimensions: {
121+
length: 1,
122+
width: 2,
123+
height: 4,
124+
},
125+
healthPoints: 10,
126+
name: 'Lilith',
127+
team: 'Forest Kingdom',
128+
weapons: [
129+
'Bow',
130+
'Dagger',
131+
],
132+
language: 'Elvish',
133+
});
134+
135+
136+
console.log(mage.createdAt); // Today's date
137+
console.log(archer.dimensions); // { length: 1, width: 2, height: 4 }
138+
console.log(swordsman.healthPoints); // 15
139+
console.log(mage.name); // Bruce
140+
console.log(swordsman.team); // The Round Table
141+
console.log(mage.weapons); // Staff of Shamalama
142+
console.log(archer.language); // Elvish
143+
console.log(archer.great()); // Lilith offers a greeting in Elvish.
144+
console.log(mage.takeDamage()); // Bruce took damage.
145+
console.log(swordsman.destroy()); // Sir Mustachio was removed from the game.

0 commit comments

Comments
 (0)