Repository navigation
Expand file tree
/
Copy pathlambda-classes.js
More file actions
172 lines (148 loc) · 4.28 KB
/
Copy pathlambda-classes.js
File metadata and controls
172 lines (148 loc) · 4.28 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
class Person {
constructor(attrs) {
this.name = attrs.name;
this.age = attrs.age;
this.location = attrs.location;
}
speak() {
console.log(`Hello, my name is ${this.name}, I am from ${this.location}`);
}
}
class Instructor extends Person {
constructor(attrs) {
super(attrs);
this.speciality = attrs.speciality;
this.favLanguage = attrs.favLanguage;
this.catchPhrase = attrs.catchPhrase;
}
demo(subject) {
console.log(
`Hello my name is ${this.name} and today we are learning about ${subject} where subject is the param passed in.`
);
}
grade(student, subject) {
console.log(`${student.name} receives a perfect score on ${subject}`);
}
changeGrade(student) {
const randomPoint = Math.ceil((Math.random() * 100) / 5); // Random number between 0 to 20
const randomOperation = Math.round(Math.random()) ? true : false;
student.grade = randomOperation
? student.grade + randomPoint // add if true
: student.grade - randomPoint; // subtract if false
const message = randomOperation
? `${this.name} added ${randomPoint} points to ${student.name}'s grade. Final grade is ${student.grade}` // addition message
: `${this.name} subtracted ${randomPoint} points from ${student.name}'s grade. Final grade is ${student.grade}`; // subtraction message
console.log(message);
}
}
class Student extends Person {
constructor(attrs) {
super(attrs);
this.previousBackground = attrs.previousBackground;
this.className = attrs.className;
this.favSubjects = attrs.favSubjects;
this.grade = attrs.grade;
}
listSubjects() {
console.log(`${this.name}'s favorite topics are:`);
return this.favSubjects.map((item, index) =>
console.log(`${index + 1}.`, item)
);
}
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() {
const gradMessage =
this.grade < 70
? `${this.name}'s grade is ${this.grade}, ergo not ready for graduation.`
: `Congratulations, ${this.name}! Your grade ${this.grade} helps you graduate this year!`;
console.log(gradMessage);
}
}
class TeamLead extends Instructor {
constructor(attrs) {
super(attrs);
this.gradClassName = attrs.gradClassName;
this.favInstructor = attrs.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 pace = new Instructor({
name: "Pace Ellsworth",
age: "33",
location: "Somewhere",
speciality: "HTML, CSS, and JS",
favLanguage: "CSS",
catchPhrase: "Allright guys"
});
const king = new Instructor({
name: "David",
age: "66",
location: "His Kingdom",
speciality: "C#",
favLanguage: "Assembly",
catchPhrase: "My reign begins"
});
const jeffrey = new TeamLead({
name: "Jeffrey Whitaker",
age: "27",
location: "Seattle",
speciality: "Redux",
favLanguage: "React",
catchPhrase: "How is everybody doing",
gradClassName: "WEB100",
favInstructor: "Pace Ellsworth"
});
const isla = new TeamLead({
name: "Isla McNail",
age: "23",
location: "USA",
speciality: "LESS",
favLanguage: "Java",
catchPhrase: "Hello everyone",
gradClassName: "WEB101",
favInstructor: "Pace Ellsworth"
});
const samet = new Student({
name: "Samet Mutevelli",
age: "29",
location: "Los Angeles",
previousBackground: "Academia",
className: "WEBPT11",
favSubjects: ["Javascript", "React", "Redux"],
grade: 70
});
const zaza = new Student({
name: "Batuhan Balta",
age: "25",
location: "Culver City",
previousBackground: "Electrical Engineer",
className: "WEBPT11",
favSubjects: ["HTML", "CSS", "LESS", "Javascript"],
grade: 75
});
pace.demo("HTML");
pace.grade(samet, "Javascript");
king.demo("Java");
king.grade(zaza, "LESS");
zaza.listSubjects();
samet.listSubjects();
zaza.PRAssignment("React");
samet.PRAssignment("Javascript");
zaza.sprintChallenge("HTML");
samet.sprintChallenge("CSS");
jeffrey.standUp("#afterhours");
isla.debugsCode(zaza, "Javascript");
pace.changeGrade(samet);
samet.graduate();