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
184 lines (164 loc) · 4.65 KB
/
Copy pathlambda-classes.js
File metadata and controls
184 lines (164 loc) · 4.65 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
// CODE here for your Lambda Classes
//////////////////////////////////////
/////////// CLASSES
//////////////////////////////////////
/////////// PERSON CLASS (BASE)
class Person {
constructor(props) {
this.name = props.name;
this.age = props.age;
this.gender = props.gender;
this.location = props.location;
}
speak() {
console.log(`Hello my name is ${this.name}, I am from ${this.location}.`);
}
}
//////////////////////////////////////
/////////// INSTRUCTOR CLASS
class Instructor extends Person {
constructor(props) {
super(props);
this.specialty = props.specialty;
this.favLanguage = props.favLanguage;
this.catchPhrase = props.catchPhrase;
}
demo(subject) {
console.log(`Today we are learning about ${subject}`);
}
grade(student, subject) {
console.log(`${student.name} receives a perfect score on ${subject}.`);
}
gradePoints(student, subject) {
let randomGrade = Math.ceil((Math.random() - 0.5) * 10);
student.grade = student.grade + randomGrade;
if (student.grade > 100) {
student.grade = 100;
}
if (student.grade < 0) {
student.grade = 0;
}
if (randomGrade > 0) {
return `${
student.name
} did well on the ${subject} test. The score improved the student's average grade by ${randomGrade}. ${
student.name
}'s average grade is now ${student.grade}.`;
}
if (randomGrade < 0) {
return `${
student.name
} did poorly on the ${subject} test. The score decreased the student's average grade by ${randomGrade}. ${
student.name
}'s average grade is now ${student.grade}.`;
} else {
return `${
student.name
} did fine on the ${subject} test. The score did not affect the student's average grade. ${
student.name
}'s average grade is still ${student.grade}.`;
}
}
}
//////////////////////////////////////
/////////// STUDENT CLASS
class Student extends Person {
constructor(props) {
super(props);
this.previousBackground = props.previousBackground;
this.className = props.className;
this.favSubjects = props.favSubjects;
this.grade = props.grade;
}
listsSubjects() {
console.log(`${this.name}'s Favourite Subjects: ${this.favSubjects}`);
}
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}'s current average grade is ${this.grade}. ${
this.name
} is allowed to Graduate.`
);
} else {
console.log(
`${this.name}'s current average is ${this.grade}. Sorry, ${
this.name
} did not pass, and is not allowed to graduate.`
);
}
}
}
//////////////////////////////////////
/////////// PROJECT MANAGER CLASS
class ProjectManager extends Instructor {
constructor(props) {
super(props);
this.gradClassName = props.gradClassName;
this.favInstructor = props.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}`);
}
}
/////////////////////////////////////////
/////////////////////////////////////////
/////////////////////////////////////////
// === CHARACTERS ===
// === Instructor ===
const bruce = new Instructor({
name: "Bruce",
location: "Gotham City",
age: 40,
gender: "male",
favLanguage: "JavaScript",
specialty: "Back-end",
catchPhrase: `To the Batmobile!`
});
// === Student ===
const robbin = new Student({
name: "Robbin",
location: "Gotham City",
age: 15,
gender: "male",
favLanguage: "JavaScript",
specialty: "Front-end",
catchPhrase: `I'm no sidekick!`,
className: "FSW16",
previousBackground: "Have done some coding",
favSubjects: ["REACT", "HTML", "CSS"],
grade: 100
});
// === Project Manager ===
const alfred = new ProjectManager({
name: "Alfred",
location: "London",
age: 87,
gender: "male",
favLanguage: "Perl",
specialty: "Back-end",
catchPhrase: `Anything else sir?`,
gradClassName: "FSW61",
faveInstructor: "Bruce"
});
bruce.speak();
bruce.demo("classes in JS");
bruce.gradePoints(robbin, "JS");
robbin.listsSubjects();
robbin.PRAssignment("Sprint Challenge");
robbin.sprintChallenge("JS Class");
console.log(robbin.grade);
robbin.graduate();
console.log(alfred.gradePoints(robbin, "JS Classes"));
alfred.standUp("FSW16");
alfred.debugsCode(robbin, "JS Classes");
bruce.grade(robbin, "Functional Programming");