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
243 lines (210 loc) · 5.33 KB
/
Copy pathlambda-classes.js
File metadata and controls
243 lines (210 loc) · 5.33 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
// CODE here for your Lambda Classes
class Person {
constructor(props) {
const {
name,
age,
location,
gender
} = props;
this.name = name;
this.age = age;
this.location = location;
this.gender = gender;
}
speak() {
return `Hello my name is ${this.name}, I am from ${this.location}`
}
}
class Instructor extends Person {
constructor(props) {
super(props)
const {
specialty,
favLanguage,
catchPhrase
} = props;
this.specialty = specialty;
this.favLanguage = favLanguage;
this.catchPhrase = catchPhrase;
}
demo(subject) {
return `Today we are learning about ${subject}`
}
grade({ name }, subject) {
return `${name} receives a perfect score on ${subject}`;
}
manageStudent(studentObj, addScore = true) {
if (studentObj instanceof Student) {
if (studentObj.grade > 70) {
return `${studentObj.name} has graduated`;
} else {
if (addScore) {
studentObj.grade = studentObj.grade + Math.floor((Math.random() * 10));
} else {
studentObj.grade = studentObj.grade - Math.floor((Math.random() * 10));
}
}
return `${studentObj.name}'s grade is ${studentObj.grade}`
} else {
return 'The student is not valid'
}
}
}
class Student extends Person {
constructor(props) {
super(props);
const {
previousBackground,
className,
favSubjects,
} = props;
this.previousBackground = previousBackground;
this.className = className;
this.favSubjects = favSubjects;
this.grade = 50;
}
listsSubjects() {
this.favSubjects.forEach(subject => {
console.log(subject);
})
}
PRAssignment(subject) {
return `${this.name} has submitted a PR for ${subject}`
}
sprintChallenge(subject) {
return `${this.name} has begun sprint challenge on ${subject}`
}
}
class ProjectManager extends Instructor {
constructor(props) {
super(props);
const {
gradClassName,
favInstructor,
} = props;
this.gradClassName = gradClassName;
this.favInstructor = favInstructor;
}
standUp(channel) {
return `${this.name} announces to ${channel}, @channel standy times!`
}
debugsCode({ name }, subject) {
return `${this.name} debugs ${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`
});
/* === Start Person test === */
const benjamin = new Person({
name: 'Benjamin',
age: 19,
gender: 'Male',
location: 'Lagos'
});
const kells = new Person({
name: 'Kells',
age: 18,
gender: 'Female',
location: 'Lagos'
});
console.log(kells.name)
console.log(kells.speak())
console.log(benjamin.name)
console.log(benjamin.speak())
/* ==End Person test == */
const jon = new Instructor({
name: 'Jon',
location: 'Wonderland',
age: 28,
gender: 'others',
favLanguage: 'ReactJs',
specialty: 'Backend',
catchPhrase: `The world is just a bunch of objects`
});
console.log(jon.demo('Advanced CSS'))
console.log(jon.grade({ name: 'Vincent' }, 'Advanced CSS'))
console.log(jon.favLanguage)
const jane = new Instructor({
name: 'Jane',
location: 'Nowhere',
age: 100,
gender: 'others',
favLanguage: 'Next Language',
specialty: 'Mid-end',
catchPhrase: `life is made up of lines of codes`
});
console.log(jane.favLanguage)
console.log(jane.catchPhrase);
console.log(jon.grade({ name: 'Doe' }, 'Javascript'))
const chinedu = new Student({
name: 'Chinedu',
age: 25,
location: 'Lagos Nigeria',
gender: 'Male',
previousBackground: 'Web Developer',
className: 'WEBEU2',
favSubjects: [
'Html', 'CSS', 'JavaScript', 'PHP', 'Laravel'
]
})
chinedu.listsSubjects();
console.log(chinedu.PRAssignment('Javascript IV'))
console.log(chinedu.sprintChallenge('Javascript IV'))
const yusuf = new Student({
name: 'Yusuf',
age: 23,
location: 'Lagos Nigeria',
gender: 'Male',
previousBackground: 'Media operator',
className: 'WEBEU2',
favSubjects: [
'Html', 'CSS', 'JavaScript'
]
})
yusuf.listsSubjects();
console.log(yusuf.PRAssignment('Javascript IV'))
console.log(yusuf.previousBackground)
const pm1 = new ProjectManager({
name: 'Sorin',
age: 28,
location: 'Iceland',
gender: 'Male',
gradClassName: 'WEBEU1',
favInstructor: 'Kneil',
specialty: 'Backend',
favLanguage: 'Javascript',
catchPhrase: 'Life is good with beautiful lines of code 😊'
})
console.log(pm1.catchPhrase)
console.log(pm1.standUp('webeu2_sorin'))
console.log(pm1.debugsCode({ name: 'Chinedu' }, 'Javascript IV'))
const foo = new ProjectManager({
name: 'Foo',
age: 28,
location: 'London',
gender: 'Male',
gradClassName: 'WEBEU1',
favInstructor: 'Bar',
specialty: 'Backend',
favLanguage: 'Javascript',
catchPhrase: 'Coding is about creating and fixing bugs 😂'
})
console.log(foo.catchPhrase)
console.log(foo.standUp('webeu2_foo'))
console.log(foo.debugsCode({ name: 'bar' }, 'Javascript IV'))
console.log(pm1.manageStudent(yusuf))
console.log(pm1.manageStudent(yusuf))
console.log(pm1.manageStudent(yusuf))
console.log(pm1.manageStudent(yusuf))
console.log(pm1.manageStudent(yusuf))
console.log(pm1.manageStudent(yusuf))
console.log(pm1.manageStudent(yusuf))
console.log(pm1.manageStudent(foo, false))