forked from bloominstituteoftechnology/JavaScript-IV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda-classes.js
More file actions
182 lines (158 loc) · 4.29 KB
/
Copy pathlambda-classes.js
File metadata and controls
182 lines (158 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// CODE here for your Lambda Classes
class Person {
constructor(obj) {
this.name = obj.name;
this.age = obj.age;
this.location = obj.location;
this.gender = obj.gender;
}
speak() {
return `Hello my name is ${this.name}, I am from ${this.location}.`;
}
}
class Instructor extends Person {
constructor(obj) {
super(obj);
this.specialty = obj.specialty;
this.favLanguage = obj.favLanguage;
this.catchPhrase = obj.catchPhrase;
}
demo(subject) {
console.log(`Today we are learning about ${subject}`);
}
grade(student, subject) {
console.log(`${student.name} receives a perfect score on ${subject}`);
}
adjustGrade(student) {
student.grade = Math.floor(Math.random() * 100) + 1;
}
}
class ProjectManager extends Instructor {
constructor(obj) {
super(obj);
this.gradClassName = obj.gradClassName;
this.favInstructor = obj.favInstructor;
}
standUp(channel) {
console.log(`${this.name} announces to ${channel}, @channel standy times!`);
}
debugsCode(student, subject) {
console.log(`${this.name} debugs ${student.name}'s code on ${subject}`);
}
}
class Student extends Person {
constructor(obj) {
super(obj);
this.previousBackground = obj.previousBackground;
this.className = obj.className;
this.favSubjects = obj.favSubjects;
this.grade = obj.grade;
}
listsSubjects() {
const arr = this.favSubjects;
console.log(`${this.name}'s favorite subjects:`);
arr.forEach((x, y) => console.log(` ${y + 1}. ${x}`));
}
PRAssignment(subject) {
console.log(`${this.name} has submitted a PR for ${subject}`);
}
sprintChallenge(subject) {
console.log(`${this.name} has begun sprint challenge on ${subject}`);
}
graduate() {
if (this.grade >= 70) {
console.log(`Congratulations ${this.name}! Your grade of ${this.grade} qualifies you for graduation.`);
} else {
const oldGrade = this.grade;
console.log(`${this.name} has a current grade of ${this.grade}%.`);
console.log(`Grading more of ${this.name}'s assignments...`);
jerry.adjustGrade(this);
console.log(`${this.name}'s grade has changed by ${this.grade - oldGrade} percentage points.`);
return this.graduate();
}
}
}
const jonathan = new Student({
name: 'Jonathan',
age: 37,
location: 'Florence, AL',
gender: 'male',
previousBackground: 'Poker',
className: 'web19',
favSubjects: ['JavaScript', 'React', 'Computer Science'],
grade: 50,
});
const bob = new Student({
name: 'Robert',
age: 32,
location: 'New Orleans, LA',
gender: 'male',
previousBackground: 'accounting',
classname: 'web18',
favSubjects: ['Node', 'Back end'],
grade: 60,
});
console.log('\n');
console.log('======================== STUDENTS =======================');
console.log(jonathan);
console.log(bob);
jonathan.PRAssignment('JavaScript-III');
bob.sprintChallenge('Advanced CSS');
jonathan.listsSubjects();
const fred = new Instructor({
name: 'Fred',
location: 'Bedrock',
age: 37,
gender: 'male',
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: `Dont't forget the homies!`,
});
const joe = new Instructor({
name: 'Joey',
location: 'New York, NY',
age: 33,
gender: 'male',
favLanguage: 'Python',
specialty: 'Back-end',
catchPhrase: `How You doin'?`,
});
console.log('\n');
console.log('====================== INSTRUCTORS ======================');
console.log(fred);
console.log(joe);
fred.demo('pseudo-classical inheritance');
joe.grade(jonathan, 'JavaScript-IV');
const jerry = new ProjectManager({
name: 'Jerry',
location: 'NYC',
age: 33,
gender: 'male',
favLanguage: 'C',
specialty: 'CS',
catchPhrase: `Hello, Newman.`,
gradClassName: 'CS1',
favInstructor: 'Josh',
});
const newman = new ProjectManager({
name: 'Newman',
location: 'NYC',
age: 37,
gender: 'male',
favLanguage: 'JS',
specialty: 'React/Redux',
catchPhrase: `Hello, Jerry.`,
gradClassName: 'CS1',
favInstructor: 'Josh',
});
console.log('\n');
console.log('=================== PROJECT MANAGERS ===================');
console.log(jerry);
console.log(newman);
newman.standUp('web19_newman');
jerry.debugsCode(bob, 'Applied JavaScript');
console.log('\n');
console.log('================= GRADUATION =================');
jonathan.graduate();
console.log('\n');
bob.graduate();