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
185 lines (160 loc) · 4.74 KB
/
Copy pathlambda-classes.js
File metadata and controls
185 lines (160 loc) · 4.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
185
// CODE here for your Lambda Classes
// creating Person class
class Person {
constructor(personAttributes) {
this.name = personAttributes.name;
this.age = personAttributes.age;
this.location = personAttributes.location;
}
speak() {
console.log(`Hello my name is ${this.name}, I am from ${this.location}`);
}
}
// creating Instructor class
class Instructor extends Person {
constructor(instructorAttributes) {
super(instructorAttributes);
this.specialty = instructorAttributes.specialty;
this.favLanguage = instructorAttributes.favLanguage;
this.catchPhrase = instructorAttributes.catchPhrase;
}
demo(subjectStr) {
console.log(`Today we are learning about ${subjectStr}`);
}
grade(studentObj, subjectStr) {
console.log(`${studentObj.name} receives a perfect score on ${subjectStr}`);
}
// stretch creating addOrSubtract method
addOrSubtract() {
// creating gradeChange, assigning it to random # between 0 - 100
let gradeChange = Math.floor(Math.random() * 101);
// if gradeChange > 50, subtract gradeChange from nicholas's grade of 80
if (gradeChange > 50) {
nicholas.grade -= gradeChange;
// else add gradeChange to nicholas's grade of 80
} else {
nicholas.grade += gradeChange;
}
}
}
//creating Student class
class Student extends Person {
constructor(studentAttributes) {
super(studentAttributes);
this.previousBackground = studentAttributes.previousBackground;
this.className = studentAttributes.className;
this.favSubjects = studentAttributes.favSubjects;
// stretch "grade" prop
this.grade = studentAttributes.grade;
}
listsSubjects() {
console.log(this.favSubjects);
}
PRAssignment(subject) {
console.log(`${this.name} has submitted a PR for ${subject}`);
}
// stretch "graduate" method
graduate() {
if (this.grade > 70) {
console.log(`${this.name}'s score is ${this.grade}! Congrats, you are ready for graduation! :)`);
} else {
console.log(`${this.name}'s score is ${this.grade}! Retake the test! :(`);
}
}
}
// creating PM class
class ProjectManager extends Instructor {
constructor(pmAttributes) {
super(pmAttributes);
this.gradClassName = pmAttributes.gradClassName;
this.favInstructor = pmAttributes.favInstructor;
}
standUp(channel) {
console.log(`${this.name} announces to ${channel}, @channel standy times!`);
}
debugsCode(studentObj, subject) {
// may have to do this.subject
console.log(`${this.name} debugs ${studentObj.name}'s code on ${subject}`);
}
}
//test Person
// 1. create marcus object with Person class
const marcus = new Person({
name: "Marcus",
age: 25,
location: "Sydney"
});
// logging marcus object
console.log(marcus);
// 2. create vlad object with Person class
const vlad = new Person({
name: "Vlad",
age: 23,
location: "USA"
});
// logging vlad object
console.log(vlad);
// 3. create samantha object with Person class
const samantha = new Person({
name: "Samantha",
age: 25,
location: "USA"
});
// logging samantha object
console.log(samantha);
// test instructor
// 1. creating fred object with Instructor class (inherits Person properties)
const fred = new Instructor({
name: "Fred",
location: "Bedrock",
age: 37,
favLanguage: "JavaScript",
specialty: "Front-end",
catchPhrase: "Don't forget the homies"
});
// logs fred object
console.log(fred);
// testing demo prototype method
fred.demo("Web Development"); // logs correctly
// testing grade prototype method
fred.grade({ name: "Marcus" }, "Web Development");
// test Student
// 1. creating nicholas object with Student class (inherits Person properties)
const nicholas = new Student({
name: "Nicholas",
age: 25,
location: "USA",
previousBackground: "Spy",
className: "Web20",
favSubjects: ["Web Development", "JavaScript", "Looking cool"],
// stretch - added grade prop, assigned to value of 80
grade: 80
});
// logging nicholas object
console.log(nicholas);
// testing listsSubject method
nicholas.listsSubjects();
// testing PRAssignment method
nicholas.PRAssignment("Preprocessing II");
// test PM
// 1. creating jamie object with Project Manager class (inherits Instructor properties that inherited Person properties)
const jamie = new ProjectManager({
name: "Jamie",
age: 30,
location: "USA",
specialty: "CSS",
favLanguage: "JavaScript",
catchPhrase: "Hey guys!",
gradClassName: "Web15",
favInstructor: "Josh"
});
// logging jamie object
console.log(jamie);
// testing standUp method
jamie.standUp("web20_jamie");
// testing debugsCode method
jamie.debugsCode({ name: "Marcus" }, "Web Development");
// testing addOrSubtract method via "jamie" PM object
jamie.addOrSubtract();
// testing graduate method via "nicholas" Student object
nicholas.graduate();