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
276 lines (246 loc) · 8.85 KB
/
Copy pathlambda-classes.js
File metadata and controls
276 lines (246 loc) · 8.85 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
// // CODE here for your Lambda Classes
// We have a school to build here! This project will get you used to thinking about classes in JavaScript and building them from a brand new data set.
// Lambda personnel can be broken down into three different types of people.
// Instructors - extensions of Person
// Students - extensions of Person
// Project Managers - extensions of Instructors
// IMPORTANT - You'll need to create 2 - 3 objects for each class and test them according to their unique Attributes.
// For example:
// const fred = new Instructor({
// name: 'Fred',
// location: 'Bedrock',
// age: 37,
// gender: 'male',
// favLanguage: 'JavaScript',
// specialty: 'Front-end',
// catchPhrase: `Don't forget the homies`
// });
// 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(property) {
this.name = property.name;
this.age = property.age;
this.location = property.location;
this.gender = property.gender;
}
speak() {
console.log `Hello, may name is ${this.name}, I am from ${this.location}.`;
}
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
}
// Instructor
// Now that we have a Person as our base class, we'll build our Instructor class.
// Instructor uses the same attributes that have been set up by Person
// Instructor has the following unique props:
// specialty what the Instructor is good at i.e. 'redux'
// favLanguage i.e. 'JavaScript, Python, Elm etc.'
// catchPhrase i.e. Don't forget the homies
// Instructor has the following methods:
// demo receives a subject string as an argument and logs out the phrase 'Today we are learning about {subject}' where subject is the param passed in.
// grade receives a student object and a subject string as arguments and logs out '{student.name} receives a perfect score on {subject}'
class Instructor extends Person {
constructor(instructorproperty) {
super(instructorproperty);
this.specialty = instructorproperty.specialty;
this.favLanguage = instructorproperty.favLanguage;
this.catchPhrase = instructorproperty.catchPhrase;
}
demo(subject) {
console.log `Today we are learning about ${subject}.`;
}
grade(Student, subject) {
console.log `${Student.name} receives a perfect score on ${subject}.`;
}
points(Student, points) {
points = getRandomInt(-10,11);
Student.grade = Student.grade + points;
console.log `${this.name} has changed ${Student.name}'s grade to ${Student.grade}.`;
}
}
// Student
// Now we need some students!
// Student uses the same attributes that have been set up by Person
// Student has the following unique props:
// previousBackground i.e. what the Student used to do before Lambda School
// className i.e. CS132
// favSubjects. i.e. an array of the student's favorite subjects ['Html', 'CSS', 'JavaScript']
// Student has the following methods:
// listsSubjects a method that logs out all of the student's favoriteSubjects one by one.
// PRAssignment a method that receives a subject as an argument and logs out that the student.name has submitted a PR for {subject}
// sprintChallenge similar to PRAssignment but logs out student.name has begun sprint challenge on {subject}
class Student extends Person {
constructor(studentproperty) {
super(studentproperty);
this.previousBackground = studentproperty.previousBackground;
this.className = studentproperty.className;
this.favSubjects = studentproperty.favSubjects;
this.grade = studentproperty.grade;
}
listSubjects() {
this.favSubjects.forEach(function(element) {
console.log(element);
});
}
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 with a grade of ${this.grade}, congratulations!`
}
else {
console.log `${this.name} needs to review and attempt the sprint challenge again. Their current grade is:${this.grade}. Time to study!`
}
}
}
// Project Mananger
// Now that we have instructors and students, we'd be nowhere without our PM's
// ProjectManagers are extensions of Instructors
// ProjectManagers have the following uniqe props:
// gradClassName: i.e. CS1
// favInstructor: i.e. Sean
// ProjectManangers have the following Methods:
// standUp a method that takes in a slack channel and logs `{name} announces to {channel}, @channel standy times!
// debugsCode a method that takes in a student object and a subject and logs out {name} debugs {student.name}'s code on {subject}
class ProjectManager extends Instructor {
constructor(pmproperty) {
super(pmproperty);
this.gradClassName = pmproperty.gradClassName;
this.favInstructor = pmproperty.favInstructor;
}
standUp(channel) {
console.log(`${this.name} announces to ${channel}, @${channel} stand-up time!`);
}
debugsCode(Student, subject) {
console.log `${this.name} debugs ${Student.name}'s code on ${subject}.`;
}
}
const fred = new Instructor({
name: 'Fred',
location: 'Bedrock',
age: 37,
gender: 'male',
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: `Don't forget the homies`
});
const josh = new Instructor({
name: 'Josh',
location: 'USA',
age: 36,
gender: 'male',
favLanguage: 'CSS',
specialty: 'Banjo',
catchPhrase: `Isn't this awesome guys?`
});
const medusa = new Instructor({
name: 'Medusa',
location: 'Underworld',
age: 999,
gender: 'female',
favLanguage: 'snake',
specialty: 'Turning you into stone',
catchPhrase: `:stares:`
});
const elvis = new Student({
name: 'Elvis',
location: 'Los Angeles',
age: 32,
gender: 'male',
favLanguage: 'the one he is currently learning',
specialty: 'walking dogs and bjj',
catchPhrase: `You ready?`,
previousBackground: 'teaching',
className: 'FSW14',
favSubjects: ['HTML/CSS', 'Javascript', 'BJJ', 'math'],
grade: 95
});
const diego = new Student({
name: 'Diego',
location: 'Chicago',
age: 31,
gender: 'male',
favLanguage: 'Python',
specialty: 'networking',
catchPhrase: `Eyyyyyyyyyyy`,
previousBackground: 'accounting',
className: 'FSW15',
favSubjects: ['taxes', 'music', 'python', 'ruby'],
grade: 20
});
const arya = new Student({
name: 'Arya',
location: 'Winterfell',
age: 16,
gender: 'female',
favLanguage: 'silence',
specialty: 'swordplay',
catchPhrase: `Not today.`,
previousBackground: 'princess',
grade: 70,
className: 'FSW16',
favSubjects: ['revenge', 'swordfighting', 'stealth']
});
const wolverine = new ProjectManager({
name: 'Wolverine',
location: 'New York',
age: 38,
gender: 'male',
favLanguage: 'english',
specialty: 'cracking jokes',
catchPhrase: `bub.`,
gradClassName: 'CS1',
favInstructor: 'Professor X',
});
const turk = new ProjectManager({
name: 'Turk',
location: 'Sacred Heart Medical',
age: 35,
gender: 'male',
favLanguage: 'bro talk',
specialty: 'surgery',
catchPhrase: `I love brinner`,
gradClassName: 'CS2',
favInstructor: 'Dr. Surgery',
});
const peach = new ProjectManager({
name: 'Princess Peach',
location: 'Mushroom Kingdom',
age: 20,
gender: 'female',
favLanguage: 'mushroom',
specialty: 'getting kidnapped by Bowser',
catchPhrase: `oh no!`,
gradClassName: 'CS3',
favInstructor: 'Queen of Mushroom Kingdom',
});
fred.demo('CSS');
medusa.grade(elvis,'python');
arya.listSubjects();
diego.PRAssignment('Javascript');
elvis.sprintChallenge('Preprocessors');
wolverine.standUp('FSW15-Wolverine');
turk.debugsCode(elvis, 'Javascript IV');
arya.speak();
peach.standUp('FSW-16-Peach');
peach.points(arya);
elvis.graduate();
diego.graduate();
arya.graduate();
// Stretch Problem
// Extend the functionality of the Student by adding a prop called grade and setting it equal to a number between 1-100.
// Now that our students have a grade build out a method on the Instructor (this will be used by BOTH instructors and PM's) that will randomly add or subtract points to a student's grade. Math.random will help.
// Add a graduate method to a student.
// This method, when called, will check the grade of the student and see if they're ready to graduate from Lambda School
// If the student's grade is above a 70% let them graduate! Otherswise go back to grading their assignments to increase their score.