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
194 lines (177 loc) · 4.94 KB
/
Copy pathlambda-classes.js
File metadata and controls
194 lines (177 loc) · 4.94 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
// CODE here for your Lambda Classes
class Person {
constructor(options) {
this.name = options.name;
this.age = options.age;
this.location = options.location;
this.gender = options.gender;
}
sayHello() {
return `Hello, my name is ${this.name}. I am from ${this.location}.`;
}
}
class Instructor extends Person {
constructor(options) {
super(options);
this.specialty = options.specialty;
this.favLanguage = options.favLanguage;
this.catchPhrase = options.catchPhrase;
}
demo(subject) {
return `Today we are learning about ${subject}.`;
}
grade(student, subject) {
return `${student.name} receives a perfect score on ${subject}.`;
}
points(student) {
var addSub = [Math.floor(student.grade + (Math.random() * (100 - student.grade))), Math.floor(student.grade - (Math.random() * (student.grade)))];
student.grade = addSub[Math.floor((Math.random() * addSub.length))];
return student.grade;
}
}
class Student extends Person {
constructor(options) {
super(options);
this.previousBackground = options.previousBackground;
this.className = options.className;
this.favSubjects = options.favSubjects;
this.grade = options.grade;
}
listsSubjects() {
return this.favSubjects;
}
PRAssignment(subject) {
return `${this.name} has submitted a PR for ${subject}.`;
}
sprintChallenge(subject) {
return `${this.name} has begun sprint challenge on ${subject}.`;
}
graduate(instructor) {
if (this.grade >= 70) {
return `Congratulations! ${this.name} has graduated!`;
}
else {
instructor.points(this);
return `Keep trying to get your score up.`;
}
}
}
class ProjectManager extends Instructor {
constructor(options) {
super(options);
this.gradClassName = options.gradClassName;
this.favInstructor = options.favInstructor;
}
standUp(channel) {
return `${this.name} announces to ${channel}, @channel standup time!`;
}
debugsCode(student, subject) {
return `${this.name} debugs ${student.name}'s code on ${subject}.`;
}
}
const fred = new Instructor({
name: 'Fred',
age: 52,
location: 'Dallas',
gender: 'M',
specialty: 'Back-end',
favLanguage: 'C++',
catchPhrase: 'What\'s a catchphrase?'
});
const mary = new Instructor({
name: 'Mary',
age: 48,
location: 'Miami',
gender: 'F',
specialty: 'Front-end',
favLanguage: 'JavaScript',
catchPhrase: 'Life is like a box of chocolates.'
});
const mike = new Instructor({
name: 'Mike',
age: 41,
location: 'Atlanta',
gender: 'M',
specialty: 'Security',
favLanguage: 'Python',
catchPhrase: 'It\'s a trap!'
});
const erin = new Student({
name: 'Erin',
age: 39,
location: 'Michigan',
gender: 'F',
previousBackground: 'none',
className: 'CS11',
favSubjects: ['CSS', 'Bootstrap', 'Javascript'],
grade: Math.floor(Math.random() *100)+1
});
const luke = new Student({
name: 'Luke',
age: 23,
location: 'Tattooine',
gender: 'M',
previousBackground: 'Moisture Farm Technician',
className: 'CS11',
favSubjects: ['Force 101', 'Lightsaber', 'X-wing piloting'],
grade: Math.floor(Math.random() *100)+1
});
const leia = new Student({
name: 'Leia',
age: 23,
location: 'Alderaan',
gender: 'F',
previousBackground: 'Imperial Senator',
className: 'CS11',
favSubjects: ['Advanced Blaster Techniques', 'Government', 'SQL'],
grade: Math.floor(Math.random() *100)+1
});
const joe = new ProjectManager({
name: 'Joe',
age: 28,
location: 'San Diego',
gender: 'M',
gradClassName: 'CS7',
favInstructor: 'Josh',
});
const anne = new ProjectManager({
name: 'Anne',
age: 32,
location: 'North Dakota',
gender: 'F',
gradClassName: 'CS3',
favInstructor: 'Josh',
});
const sam = new ProjectManager({
name: 'Sam',
age: 24,
location: 'Baltimore',
gender: 'M',
gradClassName: 'CS8',
favInstructor: 'Josh',
});
console.log(fred.name);
console.log(mary.location);
console.log(mike.specialty);
console.log(mary.favLanguage);
console.log(fred.catchPhrase);
console.log(mike.demo('JavaScript'));
console.log(erin.age);
console.log(luke.favSubjects);
console.log(leia.previousBackground);
console.log(luke.PRAssignment('CSS'));
console.log(leia.listsSubjects());
console.log(joe.debugsCode(erin, 'Python'));
console.log(sam.standUp('CS11'));
console.log(sam.sayHello());
console.log(mike.grade(leia, 'bootstrap'));
console.log(mike.points(erin));
console.log(anne.points(luke));
console.log(mike.points(leia));
console.log(joe.points(luke));
console.log(luke.grade);
console.log(erin.grade);
console.log(leia.grade);
console.log(luke.graduate(fred));
console.log(erin.graduate(mary));
console.log(leia.graduate(mike));