Repository navigation
Expand file tree
/
Copy pathlambda-classes.js
More file actions
153 lines (136 loc) · 4.09 KB
/
Copy pathlambda-classes.js
File metadata and controls
153 lines (136 loc) · 4.09 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
// CODE here for your Lambda Classes
/**
* Person Class
*/
class Person {
constructor(attributes) {
this.name = attributes.name;
this.age = attributes.age;
this.gender = attributes.gender;
this.location = attributes.location;
}
speak() {
return console.log(`Hello my name is ${this.name}, I am from ${this.location}`)
}
}
const fred = new Person({name: 'Fred', age: 12, gender: 'male', location: 'Bedrock'});
const pascal = new Person({name: 'Pascal', age: 92, gender: 'male', location: 'Lagos'});
fred.speak();
pascal.speak();
/**
* Instructor Class
*/
class Instructor extends Person {
constructor(instructorAttr) {
super(instructorAttr)
this.specialty = instructorAttr.specialty
this.favLanguage = instructorAttr.favLanguage
this.catchPhrase = instructorAttr.catchPhrase
}
demo(subject) {
return console.log(`Today we are learning about ${subject}`)
}
grade(student, subject){
return console.log(`${student.name} receives a perfect score on ${subject}`)
}
updateGrade(student) {
const randomIndex = Math.floor(Math.random()*10);
if(randomIndex%2 === 0) {
student.grade += Math.floor(Math.random()*10);
return console.log(`${student.name} increased to ${student.grade}`)
} else {
student.grade -= Math.floor(Math.random()*10);
return console.log(`${student.name}'s decreased to ${student.grade}`)
}
}
}
const joe = new Instructor(
{
name: 'Joe',
age: 12,
gender: 'male',
location: 'Bedrock',
specialty: 'Data Science',
favLanguage: 'Python',
catchPhrase: 'In God We trust'
});
// Mock of student data
let student={name: 'Paul'}
console.log(joe);
joe.demo('Java');
joe.grade(student, 'Data Science');
/**
* Student Class
*/
class Student extends Person {
constructor(studentAttr){
super(studentAttr)
this.previousBackground = studentAttr.previousBackground;
this.className = studentAttr.className;
this.favSubjects = studentAttr.favSubjects
this.grade = 75
}
listsSubjects() {
this.favSubjects.forEach(subject => {
return console.log(subject);
});
}
PRAssignment(subject) {
return console.log(`a method that receives a subject as an argument and logs out that the ${this.name} has submitted a PR for ${subject}`)
}
sprintChallenge(subject){
return console.log(`similar to PRAssignment but logs out ${this.name} has begun sprint challenge on ${subject}`)
}
graduate(reviewer){
if (this.grade >= 70){
return console.log(`congratulations ${this.name} you graduated with ${this.grade}`);
} else {
return console.log(`sorry you didn't make the cut off mark ${reviewer.updateGrade(this)}`)
}
}
}
const johnson = new Student({
name: 'Johnson',
age: 12,
gender: 'male',
location: 'Bedrock',
previousBackground: 'Data science background',
className: 'Math 405',
favSubjects: ['Java', 'CSS', 'ReactJS', 'Python']
})
console.log(johnson);
johnson.listsSubjects();
johnson.PRAssignment('Java');
johnson.sprintChallenge('Python');
johnson.graduate(joe);
/**
* Project Manager Class
*/
class ProjectManager extends Instructor {
constructor(pmAttr) {
super(pmAttr)
this.gradClassName = pmAttr.gradClassName;
this.favInstructor = pmAttr.favInstructor;
}
standUp(channel) {
return console.log(`${this.name} announces to ${channel}, @channel standup times!`)
}
debugsCode(student, subject) {
return console.log(`${this.name} debugs ${student.name}'s code on ${subject}`)
}
}
const matt = new ProjectManager({
name: 'Matt',
age: 22,
gender: 'male',
location: 'Bedrock',
specialty: 'Data Science',
favLanguage: 'Python',
catchPhrase: 'In God We trust',
gradClassName: 'WEBEU2',
favInstructor: 'Gabe'
})
console.log(matt);
matt.standUp('WebSprint');
matt.debugsCode(johnson, 'Javascript');
matt.updateGrade(johnson);