Repository navigation
Expand file tree
/
Copy pathlambda-classes.js
More file actions
229 lines (173 loc) · 4.75 KB
/
Copy pathlambda-classes.js
File metadata and controls
229 lines (173 loc) · 4.75 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// CODE here for your Lambda Classes
// Person
// First we need a Person class. This will be our base-class
// Person receives name age location gender all as props
// Person receives speak as a method.
// This method logs out a phrase Hello my name is Fred, I am from Bedrock where name and location are the object's own props
//
class Person {
constructor(object) {
this.name = object.name;
this.age = object.age;
this.location = object.location;
}
speak() {
console.log(`Hello my name is ${this.name}, I am from ${this.location}`);
}
}
const doc = new Person({
name: 'Doc',
age: 20,
location: 'California'
});
console.log(doc);
doc.speak();
// Instructor
class Instructor extends Person {
constructor(object) {
super(object);
this.specialty = object.specialty;
this.favLanguage = object.favLanguage;
this.catchPhrase = object.catchPhrase;
}
demo(subject) {
console.log(`Today we are learning about ${subject}`);
}
grade(student, subject) {
console.log(`${student.name} receives a perfect score on ${subject}`);
}
gradeStudent(student) {
let randomNumber = Math.floor(Math.random() * 20)
if (student.grade > 50) {
student.grade = student.grade - randomNumber;
} else {
student.grade = student.grade + randomNumber;
}
}
}
const grumpy = new Instructor({
name: 'Grumpy',
age: 31,
location: 'Utah',
specialty: 'Javascript',
favLanguage: 'HTML',
catchPhrase: 'Go to hell!'
})
const happy = new Instructor({
name: 'Happy',
age: 33,
location: 'Pennsylvania',
specialty: 'React',
favLanguage: 'C',
catchPhrase: 'You are beautiful'
})
console.log(grumpy);
grumpy.demo('Slack');
grumpy.grade({name: 'Bashful'}, 'Javascript');
console.log(happy);
happy.demo('Tables');
happy.grade({name: 'John'}, 'CSS');
// Student
class Student extends Person {
constructor(object) {
super(object);
this.previousBackground = object.previousBackground;
this.className = object.className;
this.favSubjects = object.favSubjects; // array
this.grade = object.grade;
}
listsSubjects() {
this.favSubjects.forEach(subject => console.log(subject));
}
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(instructor) {
const requiredGrade = 70;
if (this.grade >= requiredGrade) {
console.log(`${this.name} has a grade of ${this.grade}. Congrats, you graduated from Lambda School`);
return;
}
instructor.gradeStudent(this);
console.log(`${this.name} has failed. He has been graded again by ${instructor.name} and the new grade is ${this.grade}`);
}
}
const bashful = new Student({
name: 'Bashful',
age: 21,
location: 'Pennsylvania',
previousBackground: 'Mechanic',
className: 'WEBPT5',
favSubjects: ['Javascript', 'HTML', 'CSS'],
grade: 94
})
const dopey = new Student({
name: 'Dopey',
age: 21,
location: 'New Mexico',
previousBackground: 'Fisherman',
className: 'WEB6',
favSubjects: ['React', 'Javascript', 'HTML', 'CSS'],
grade: 12
})
console.log(bashful);
bashful.listsSubjects();
bashful.PRAssignment('Javascript IV');
bashful.sprintChallenge('Airport website');
bashful.speak();
grumpy.gradeStudent(bashful);
console.log(`${bashful.name}'s grade is now: ${bashful.grade}`);
bashful.graduate(grumpy);
console.log(dopey);
dopey.listsSubjects();
dopey.PRAssignment('Watershed project');
dopey.sprintChallenge('Javascript Challenge');
dopey.speak();
grumpy.gradeStudent(dopey);
console.log(`${dopey.name}'s grade is now: ${dopey.grade}`);
dopey.graduate(grumpy);
// Project Manager
class ProjectManager extends Instructor {
constructor(object) {
super(object);
this.gradClassName = object.gradClassName;
this.favInstructor = object.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}`);
}
}
const sleepy = new ProjectManager({
name: 'Sleepy',
age: 21,
location: 'Montana',
specialty: 'Javascript',
favLanguage: 'CSS',
catchPhrase: 'Hello howdy',
gradClassName: 'CS1',
favInstructor: 'Sean'
})
console.log(sleepy);
sleepy.speak();
sleepy.standUp('webpt5_nate');
sleepy.debugsCode({name: 'Cesare'}, 'React');
const sneezy = new ProjectManager({
name: 'Sneezy',
age: 31,
location: 'Idaho',
specialty: 'HTML',
favLanguage: 'Javascript',
catchPhrase: 'You are a potato',
gradClassName: 'CS4',
favInstructor: 'Grumpy'
})
console.log(sneezy);
sneezy.speak();
sneezy.standUp('webpt5_nate');
sneezy.debugsCode({name: 'Dopey'}, 'React');