-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildinganOOP.js
More file actions
58 lines (50 loc) · 1.16 KB
/
buildinganOOP.js
File metadata and controls
58 lines (50 loc) · 1.16 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
// 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 = "Tom", age = 20, energy = 100, xp = 0, hourlyWage = 10) {
super(name, age, energy);
this.xp = xp;
this.hourlyWage = hourlyWage;
}
doSomethingFun() {
super.doSomethingFun;
}
sleep() {
super.sleep;
}
goToWork() {
this.xp += 10;
}
}
// Task 3: Code an intern object, run methods
function intern() {
let intern = new Worker();
intern.name = "Bob";
intern.age = 21;
intern.energy = 110;
intern.xp = 0;
intern.hourlyWage = 10;
intern.goToWork();
return intern;
}
// Task 4: Code a manager object, methods
function manager() {
let manager = new Worker("Alice", 30, 120, 100, 30);
manager.doSomethingFun();
return manager;
}
console.log(intern());
console.log(manager());