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
224 lines (200 loc) · 5.51 KB
/
Copy pathlambda-classes.js
File metadata and controls
224 lines (200 loc) · 5.51 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
// CODE here for your Lambda Classes
class Person {
constructor(attributes) {
this.name = attributes.name;
this.age = attributes.age;
this.location = attributes.location;
}
speak() {
console.log(`Hello, my name is ${this.name}. I am from ${this.location}.`);
}
}
class Instructor extends Person {
constructor(attributes) {
super(attributes);
this.specialty = attributes.specialty;
this.favLanguage = attributes.favLanguage;
this.catchPhrase = attributes.catchPhrase;
}
demo(subject) {
console.log(`Today we are learning about ${subject}.`);
}
grade(student, subject) {
console.log(`${student.name} receives a perfect score on ${subject}.`);
}
tests(student) {
if (Math.random() < 0.6) {
let points = Math.floor(Math.random() * 4 + 2);
student.grade += points;
console.log(`${this.name} adds ${points} points to ${student.name}'s grade`);
} else {
let points = Math.floor(Math.random() * 3 + 1);
if (points < student.grade) {
student.grade -= points;
console.log(`Oh noes! ${this.name} deducts ${points} points from ${student.name}'s grade`);
} else {
student.grade = 0;
console.log(`Oh geez this is bad, this is so bad, ${student.name} just screwed up so hard that ${this.name} said "go start everything all over!"`)
}
}
}
}
class Student extends Person {
constructor(attributes) {
super(attributes);
this.previousBackground = attributes.previousBackground;
this.className = attributes.className;
this.favSubjects = attributes.favSubjects;
this.grade = attributes.grade;
}
listsSubjects() {
this.favSubjects.forEach(function(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() {
if (this.grade > 70) {
console.log(this.name + " is ready to graduate Lambda School!");
} else {
console.log(`${this.name} isn't quite ready to graduate. Only ${71 - this.grade} points to go!`);
}
}
}
class ProjectManager extends Instructor {
constructor(attributes) {
super(attributes);
this.gradClassName = attributes.gradClassName;
this.favInstructor = attributes.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}.`);
}
}
// ===== templates =====
/*
const ******** = new Student({
name: ,
age: ,
location: ,
previousBackground: ,
className: ,
favSubjects: []
});
const ******** = new Instructor({
name: ,
age: ,
location: ,
speciality: ,
favLanguage: ,
catchPhrase:
});
const ******** = new ProjectManager({
name: ,
age: ,
location: ,
speciality: ,
favLanguage: ,
catchPhrase: ,
gradClassName: ,
favInstructor:
});
*/
const ang = new Student({
name: "Angela",
age: 35,
location: "Pittsburgh",
previousBackground: "SharePoint janitor",
className: "WEB22",
favSubjects: ["JavaScript", "CSS"],
grade: 50
});
ang.speak();
const bob = new Student({
name: "Bob",
age: 28,
location: "Peoria, IL",
previousBackground: "chef",
className: "WEB20",
favSubjects: ["Javascript", "SQL", "C"],
grade: 3
})
bob.listsSubjects();
const carol = new Student({
name: "Carol",
age: 44,
location: "Chicago",
previousBackground: "loan officer",
className: "UX Design",
favSubjects: ["CSS", "design", "measuring pixels with a ruler"],
grade: 75
});
ang.PRAssignment("JavaScript IV");
bob.sprintChallenge("Node");
const dave = new Instructor({
name: "Dave",
age: 38,
location: "San Francisco",
speciality: "SQL",
favLanguage: "Python",
catchPhrase: "That is all, and that's enough.",
});
const emma = new Instructor({
name: "Emma",
age: "33",
location: "Seattle",
speciality: "mobile design",
favLanguage: "JavaScript",
catchPhrase: "Of course, that's just my opinion",
});
console.log(JSON.stringify(dave));
dave.demo("CSS");
emma.grade(ang, "JavaScript IV");
const fred = new ProjectManager({
name: "Fred",
age: 40,
location: "Boston",
speciality: "yelling at everyone to get their Airtable in",
favLanguage: "C++",
catchPhrase: "I know you are, but what am I?",
gradClassName: "WEB19",
favInstructor: dave
});
const ginger = new ProjectManager({
name: "Ginger",
age: 37,
location: "Milwaukee",
speciality: "monitoring Zoom to be sure all the cameras are on",
favLanguage: "JavaScript",
catchPhrase: "",
gradClassName: "WEB20",
favInstructor: emma
});
fred.favInstructor.speak();
fred.standUp();
fred.debugsCode(bob, "a big mess of prototype declarations");
bob.graduate();
carol.graduate();
ginger.tests(bob);
fred.tests(ang);
ginger.tests(ang);
dave.tests(ang);
emma.tests(ang);
ang.graduate();
fred.tests(ang);
fred.tests(ang);
fred.tests(ang);
fred.tests(ang);
ang.graduate();
fred.tests(ang);
fred.tests(ang);
fred.tests(ang);
ang.graduate();