Repository navigation
Expand file tree
/
Copy pathlambda-classes.js
More file actions
164 lines (129 loc) · 4.34 KB
/
Copy pathlambda-classes.js
File metadata and controls
164 lines (129 loc) · 4.34 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
class Person {
constructor(obj) {
this.name = obj.name;
this.age = obj.age;
this.location = obj.location;
}
speak() {
console.log(`Hello my name is ${this.name}, I am from ${this.location}`);
}
}
class Instructor extends Person {
constructor(obj) {
super(obj);
this.specialty = obj.specialty;
this.favLanguage = obj.favLanguage;
this.catchPhrase = obj.catchPhrase;
}
demo(subject) {
console.log(`Today we are learning about ${subject}`);
}
grade(student, subject) {
console.log(`${student.name} receives a perfect score on ${subject}`);
}
}
class Student extends Person {
constructor(obj) {
super(obj);
this.previousBackground = obj.previousBackground;
this.className = obj.className;
this.favSubjects = obj.favSubjects;
}
listsSubjects() {
this.favSubjects.forEach(function (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}`);
}
}
class ProjectManager extends Instructor {
constructor(obj) {
super(obj);
this.gradClassName = obj.gradClassName;
this.favInstructor = obj.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 fred = new Instructor({
name: 'Fred',
location: 'Bedrock',
age: 37,
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: `Don't forget the homies`
});
const derper = new Student({
name: 'Derper',
location: 'Mars',
age: 15,
favLanguage: 'Python',
specialty: 'machine learning',
catchPhrase: `I let my computer learn for me`,
previousBackground: 'mumble rapper',
className: "ML90000",
favSubjects: ["astrophysics", "science fiction", "biology"]
});
const noSleep = new ProjectManager({
name: 'No Sleep',
location: 'Hell',
age: 999,
favLanguage: 'Binary',
specialty: 'opcodes',
catchPhrase: `What is life?`,
previousBackground: 'crossing guard',
className: "T-1000",
favSubjects: ["neuroscience of sleep deprivation"],
gradClassName: "I don't know what this is supposed to be",
favInstructor: "stackoverflow.com"
});
//tests Person method
noSleep.speak();
//tests Instructor methods
fred.demo("artificial intelligence");
fred.grade(derper, "astrophysics");
//tests Student methods
derper.listsSubjects();
derper.sprintChallenge("biology");
derper.PRAssignment("science fiction");
//tests Project Manager methods
noSleep.standUp('night owls');
noSleep.debugsCode(derper, "javascript");
/*
#### Stretch Problem
* Extend the functionality of the Student by adding a prop called grade and setting it equal to a number between 1-100.
* Now that our students have a grade build out a method on the Instructor (this will be used by _BOTH_ instructors and PM's) that will randomly add or subtract points to a student's grade. _Math.random_ will help.
* Add a graduate method to a student.
* This method, when called, will check the grade of the student and see if they're ready to graduate from Lambda School
* If the student's grade is above a 70% let them graduate! Otherwise go back to grading their assignments to increase their score.
*
* */
Student.prototype.grade = 70;
console.log(derper.grade); //tests that derper now has a grade
Instructor.prototype.randomizeGrade = function (student) {
randNum = Math.random() * 10;
if (randNum > 5) {
student.grade += randNum;
} else {
student.grade -= randNum;
}
console.log(student.grade);
}
fred.randomizeGrade(derper); //tests the randomizeGrade function on fred and derper
Student.prototype.graduate = function () {
if (this.grade > 70) {
return `${this.name} has a passing grade of ${this.grade} and has now officially graduated!`;
} else {
return `${this.name} has a failing grade of ${this.grade} and has now officially failed!`;
}
}
console.log(derper.graduate()); //tests the graduate function on derper