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
201 lines (155 loc) · 5.74 KB
/
Copy pathlambda-classes.js
File metadata and controls
201 lines (155 loc) · 5.74 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
class Person {
constructor(attributes) {
this.name = attributes.name;
this.age = attributes.age;
this.location = attributes.location;
this.gender = attributes.gender;
}
// Methods
speak() {
return `Hello my name is ${this.name}, I am from ${this.location}.`;
}
}
class Instructor extends Person { // Child of Person
// always in strict mode
constructor(instructorAttributes) {
super(instructorAttributes) // similar to Object.create
this.speciality = instructorAttributes.speciality;
this.favLanguage = instructorAttributes.favLanguage;
this.catchPhrase = instructorAttributes.catchPhrase;
}
// Methods
demo(subject) {
if (!subject) {subject = lukeSubjects[Math.floor(Math.random()*lukeSubjects.length) ]};
return `Today we are learning about ${subject}.`;
}
grade(student, subject) {
if (!student) {student = lukeSkywalker}
if (!subject) {subject = lukeSubjects[Math.floor(Math.random()*lukeSubjects.length) ]};
return `${student.name} receives a perfect score on ${subject}.`;
}
nextAssignment (student) {
if (!student) {student = lukeSkywalker};
let currStudentScore = `${student.grade()}`;
let plusMinus = 0;
Math.random() > 0.5 ? plusMinus = -1: plusMinus = 1;
let assignmentScore = Math.floor(Math.random()*10) * plusMinus;
return parseInt(`${currStudentScore} + ${assignmentScore}`);
}
}
class Student extends Person{ // Child of Person
// always in strict mode
constructor(studentAttributes) {
super(studentAttributes) // similar to Object.create
this.previousBackground = studentAttributes.previousBackground;
this.className = studentAttributes.className;
this.favSubjects = studentAttributes.favSubjects;
}
// Methods
listSubjects() {
let allSubjects = `${this.favSubjects}`
return allSubjects.split(',');
}
PRAssignment(subject) {
if (!subject) {subject = lukeSubjects[Math.floor(Math.random()*lukeSubjects.length) ]};
return `${this.name} has submitted a PR for ${subject}.`;
}
sprintChallenge(subject) {
if (!subject) {subject = lukeSubjects[Math.floor(Math.random()*lukeSubjects.length) ]};
return `${this.name} has begun a sprint challenge on ${subject}.`;
}
grade() {
return Math.floor(Math.random()*100);
}
gitCurrGrade() {
let currGrade = `${this.grade()}` * 1;
return currGrade;
}
graduate() {
const currGraduatingScore = `${this.gitCurrGrade()}` * 1;
currGraduatingScore + `${yoda.nextAssignment()}`;
// console.log(`currGraduatingScore`, currGraduatingScore)
return currGraduatingScore >= 70 ? `Congrats! Your final grade is ${currGraduatingScore}%. You are a Jedi!`: this.graduate();
}
}
class ProjectManager extends Instructor{ // Child of Instructor
// always in strict mode
constructor(pmAttributes) {
super(pmAttributes) // similar to Object.create
this.gradClassName = pmAttributes.gradClassName;
this.favInstructor = pmAttributes.favInstructor;
}
// Methods
standUp(slackChannel) {
const slackArr =['Blast!', 'Laserbrain', 'Walking-carpet', 'Scruffy-looking-Nerfherder', 'Flyboy', 'Son-of-a-Bantha', 'Thank-the-Maker', 'Droid-Work']
if (!slackChannel) {slackChannel = slackArr[Math.floor(Math.random()*slackArr.length) ]}
return `${this.name} announces to @${slackChannel} standy times!`;
}
debugsCode(student, subject) {
if (!student) {student = lukeSkywalker};
if (!subject) {subject = lukeSubjects[Math.floor(Math.random()*lukeSubjects.length) ]};
return `${this.name} debugs ${lukeSkywalker.name}'s code on ${subject}.`;
}
}
const yoda = new Instructor({
name: 'Yoda',
age: 900,
location: 'Dagobah',
gender: 'M',
speciality: 'The Force',
favLanguage: ['Object-Subject-Verb', 'Galactic Basic', 'inspirational speeches'],
catchPhrase: "Do, or do not. There is no try.",
});
const lukeSkywalker = new Student({
name: 'Luke Skywalker',
age: 19,
location: 'Tatooine',
gender: 'M',
previousBackground: ['farming', 'droids'],
className: 'Young Jedi',
favSubjects: ['aviation', 'The Force', 'lightsaber training'],
});
const anakinSkywalker = new Student({
name: 'Anakin Skywalker',
age: 45,
location: 'Tatooine',
gender: 'M',
previousBackground: ['slave'],
className: 'Padawan',
favSubjects: ['racing podracing', 'repairing droids', 'The Force', 'lightsaber training'],
});
const oldBenKenobi = new ProjectManager({
name: 'Obi-Wan Kenobi',
age: 57,
location: 'everywhere. I am omnipresent',
gender: 'M',
speciality: 'Sith Lords',
favLanguage: ['Galactic Basic', 'Shyriiwook'],
catchPhrase: 'Use the Force, Luke',
});
const allStudents = [lukeSkywalker, anakinSkywalker];
const lukeSubjects = lukeSkywalker.listSubjects();
const anakinSubjects = anakinSkywalker.listSubjects();
// let gitStatus = `${lukeSkywalker.graduate()}`;
// console.log(gitStatus);
console.log(lukeSkywalker.speak());
console.log(yoda.speak());
console.log(oldBenKenobi.speak());
console.log(yoda.demo());
console.log(yoda.demo('Princesses'));
console.log(yoda.grade(lukeSkywalker));
console.log(yoda.nextAssignment(anakinSkywalker))
console.log(lukeSkywalker.listSubjects());
console.log(lukeSkywalker.sprintChallenge());
console.log(lukeSkywalker.PRAssignment());
console.log(anakinSkywalker.listSubjects());
console.log(anakinSkywalker.sprintChallenge());
console.log(anakinSkywalker.PRAssignment());
console.log(anakinSkywalker.grade())
console.log(lukeSkywalker.graduate());
console.log(anakinSkywalker.graduate());
console.log(oldBenKenobi.standUp());
console.log(oldBenKenobi.debugsCode());
console.log(oldBenKenobi.demo());
console.log(oldBenKenobi.grade(anakinSkywalker));