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
169 lines (149 loc) · 4.13 KB
/
Copy pathlambda-classes.js
File metadata and controls
169 lines (149 loc) · 4.13 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
// Person Class
class Person {
constructor(attr) {
this.name = attr.name;
this.age = attr.age;
this.location = attr.location;
this.gender = attr.gender;
}
speak() {
console.log(`Hello my name is ${this.name}, I am from ${this.location}`);
}
}
// Instructor Class inherits from Person Class
class Instructor extends Person {
constructor(attr) {
super(attr);
this.speciality = attr.speciality;
this.favLanguage = attr.favLanguage;
this.catchphrase = attr.catchphrase;
}
demo(subject) {
console.log(`Today we are learning about ${subject}`);
}
grade(student, subject) {
console.log(`${student.name} receives a perfect score on ${subject}`);
}
updateGrade(student) {
if (Math.floor(Math.random() * 2) === 0) {
student.grade += 10;
} else {
student.grade -= 10;
}
return `${student.name}'s grade is now ${student.grade}`;
}
}
// Student Class inherits from person class
class Student extends Person {
constructor(attr) {
super(attr);
this.previousBackground = attr.previousBackground;
this.className = attr.className;
this.favSubjects = attr.favSubjects;
this.grade = attr.grade;
this.hasGraduated = false;
}
graduate(caller) {
if (!this.hasGraduated && this.grade > 70) {
this.hasGraduated = true;
console.log(
`Well Done, ${this.name}! You have graduated from Lambda School!!!`
);
} else {
caller.updateGrade(this);
}
}
listsSubjects() {
this.favSubjects.forEach(subject => {
console.log(subject);
});
}
PRAssignment(subject) {
console.log(`${this.name} has submitted a PR for ${subject}`);
}
sprintChallenge(subject) {
console.log(`${this.name} has begun sprint challenge on ${subject}`);
}
}
// ProjectManager class extends Instructor class
class ProjectManager extends Instructor {
constructor(attr) {
super(attr);
this.gradeClassName = attr.gradeClassName;
this.favInstructor = attr.faveInstructor;
}
standUp(channel) {
console.log(
`${this.name} announces to ${channel}, @channel standy times!`
);
}
debugCode(student, subject) {
console.log(`${name} debugs ${student.name}'s code on ${subject}`);
}
}
// starting the tests
// student to test on
const tom = new Student({
name: "Tom Tarpey",
location: "Prestatyn",
age: 39,
previousBackground: "Network Security",
className: "CS13",
favSubjects: ["C++", "Assembly", "JuJitSu"],
grade: 70
});
const bambam = new Student({
name: "Bam Bam",
location: "Bedrock",
age: 39,
previousBackground: "Construction",
className: "CS13",
favSubjects: ["Rock Climbing", "JavaScript", "Saying Bam Bam!"],
grade: 30
});
// instructor to test on
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 Knell",
location: "The Internet",
age: 39,
gender: "male",
favLanguage: "JavaScript",
specialty: "Front-end",
catchPhrase: `I have a particular set of skills!`
});
// project manager to test on
const barney = new ProjectManager({
name: "Barney Rubble",
location: "Bedrock",
age: 26,
gradClassName: "CS13",
favInstructor: "Fred"
});
const charletta = new ProjectManager({
name: "Charletta Bullard",
location: "Lambda",
age: 26,
gradClassName: "CS13",
favInstructor: "Josh"
});
fred.speak(); // --> Hello my name is Fred, I am from Bedrock
tom.listsSubjects(); // --> C++ Assembly JuJitSu
fred.demo("The way of the porcupine III"); // --> Today we are learning about The way of the porcupine III
barney.standUp("Food Tek with video Toasters"); // --> Barney Rubble announces to Food Tek with video Toasters, @channel standy times!
console.log(tom.grade); // --> 50
fred.updateGrade(tom);
console.log(tom.grade); // --> 40 or 60
tom.graduate(fred);
bambam.graduate(charletta);
console.log(charletta.name); // --> Charletta Bullard
tom.graduate(josh);
console.log(josh.name) // --> Josh Knell