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
151 lines (140 loc) · 4.44 KB
/
Copy pathlambda-classes.js
File metadata and controls
151 lines (140 loc) · 4.44 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
class Person {
constructor(baseAttr) {
this.name = baseAttr.name;
this.age = baseAttr.age;
this.location = baseAttr.location;
this.gender = baseAttr.gender;
}
speak() {
return `Hello, my name is ${this.name}, I am from ${this.location}.`;
}
}
class Instructor extends Person {
constructor(instructorAttr) {
super(instructorAttr);
this.specialty = instructorAttr.specialty;
this.favLanguage = instructorAttr.favLanguage;
this.catchPhrase = instructorAttr.catchPhrase;
}
demo(subject) {
return `Today we are learning about ${subject}.`;
}
grade(student, subject) {
return `${student.name} receives a perfect score on ${subject}.`;
}
distributePoints(student) {
let addOrSubtract = Math.random();
if (addOrSubtract > 0.5) {
student.grade += Math.floor(Math.random() * Math.random() * 10);
return `Points awarded to ${student.name}! Current grade: ${student.grade}`;
} else {
student.grade -= Math.floor(Math.random() * Math.random() * 10);
return `Points deducted from ${student.name}! Current grade: ${student.grade}`;
}
}
}
class Student extends Person {
constructor(studentAttr) {
super(studentAttr);
this.previousBackground = studentAttr.previousBackground;
this.className = studentAttr.className;
this.favSubjects = studentAttr.favSubjects;
this.grade = studentAttr.grade;
}
listsSubjects() {
return this.favSubjects.toString();
}
PRAssignment(subject) {
return `${this.name} has submitted a PR for ${subject}.`;
}
sprintChallenge(subject) {
return `${this.name} has begun sprint challenge on ${subject}.`;
}
graduate() {
return (this.grade < 70 ? 'You didn\'t graduate! ~_~ Try again!' : 'You graduated! :D');
}
}
class ProjectManager extends Instructor {
constructor(PMAttr) {
super(PMAttr);
this.gradClassName = PMAttr.gradClassName;
this.favInstructor = PMAttr.favInstructor;
}
standUp(channel) {
return `${this.name} announces to ${channel}, @channel standy times!`;
}
debugsCode(student, subject) {
return `${this.name} debugs ${student.name}'s code on ${subject}`;
}
}
const josh = new Instructor({
name: 'Josh',
location: 'Zoom Meeting Client',
age: 'eternal',
gender: 'male',
specialty: 'instructing',
favLanguage: 'ActionScript 3',
catchPhrase: 'This is the inline-block to flexbox!'
});
const bigBoss = new Instructor({
name: 'BIG BOSS',
location: 'EVERYWHERE',
age: 1000,
gender: 'ALL',
specialty: 'ALL',
favLanguage: 'REGEX',
catchPhrase: 'NEED THOSE REPORTS'
});
const lola = new Student({
name: 'Lola',
location: 'Philadelphia suburbs',
age: 21,
gender: 'female',
previousBackground: 'Pre-med student; just finished B.S. in Health Sciences',
className: 'FSW14',
favSubjects: ['Flexbox', 'LESS', 'JS Classes', 'JS Array Methods'],
grade: 90
});
const stuart = new Student({
name: 'Stuart Little',
location: 'New York City',
age: 15,
gender: 'male',
previousBackground: 'Anthropomorphic mouse',
className: 'FSW20',
favSubjects: ['HTML', 'CSS', 'JavaScript'],
grade: 50
});
const bill = new ProjectManager({
name: 'Bill',
location: '#FSW14_help',
age: 'eternal',
gender: 'male',
specialty: 'managing projects',
favLanguage: 'ES6',
catchPhrase: 'Today was tough, but you know, tomorrow - well, actually - tomorrow will be tougher.',
gradClassName: 'FSWinfinite',
favInstructor: 'Josh, probably'
});
const geralt = new ProjectManager({
name: 'Geralt of Rivia',
location: 'Kaer Morhen',
age: 100,
gender: 'male',
specialty: 'being a witcher',
favLanguage: 'Polish',
catchPhrase: 'Have you seen a girl with ashen hair?',
gradClassName: 'FSW3',
favInstructor: 'Harshness of Life'
});
console.log(josh.demo('JS Classes'));
console.log(bigBoss.grade(lola, 'User Interface'));
console.log(lola.listsSubjects());
console.log(lola.PRAssignment('prototypes'));
console.log(stuart.sprintChallenge('JavaScript'));
console.log(bill.standUp('#FSW14_bill'));
console.log(geralt.debugsCode(stuart, 'closures'));
console.log(geralt.speak());
console.log(bigBoss.distributePoints(stuart));
console.log(lola.graduate());
console.log(stuart.graduate());