-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoop lab solution.js
More file actions
43 lines (37 loc) · 885 Bytes
/
oop lab solution.js
File metadata and controls
43 lines (37 loc) · 885 Bytes
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
// Task 1: Code a Person class
class Person {
constructor(name = "Tom", age = 20, energy = 100) {
this.name = name;
this.age = age;
this.energy = energy;
}
sleep() {
this.energy += 10;
}
doSomethingFun() {
this.energy -= 10;
}
}
// Task 2: Code a Worker class
class Worker extends Person {
constructor(name, age, energy, xp = 0, hourlyWage = 10) {
super(name, age, energy);
this.xp = xp;
this.hourlyWage = hourlyWage;
}
goToWork() {
this.xp += 10;
}
}
// Task 3: Code a intern object
function intern() {
const intern = new Worker("Bob", 21, 110, 0, 10);
intern.goToWork();
return intern;
}
// Task 4: Code a manager object
function manager() {
const manager = new Worker("Alice", 30, 120, 100, 30);
manager.doSomethingFun();
return manager;
}