forked from truecodersio/JavaScript_OOP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
129 lines (94 loc) · 2.24 KB
/
app.js
File metadata and controls
129 lines (94 loc) · 2.24 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
console.log("Hello World!\n==========\n");
// Exercise 1 Section
console.log("EXERCISE 1:\n==========\n");
class Person {
constructor(name, pets, residence, hobbies) {
this.name = name;
this.pets = pets;
this.residence = residence;
this.hobbies = hobbies;
}
info() {
}
soundOff() {
}
addHobby(hobby) {
this.hobbies.push(hobby);
}
removeHobby(hobby) {
let index = this.hobbies.indexOf(hobby);
this.hobbies.splice(index, 1);
}
greeting() {
console.log("Hello fellow person!")
}
}
// Exercise 2 Section
console.log("EXERCISE 2:\n==========\n");
class Coder extends Person {
constructor(name, pets, residence, hobbies, occupation) {
super(name, pets, residence, hobbies)
this.occupation = occupation;
}
greeting() {
console.log("Hi, I code.")
}
}
// Exercise 3 Section
console.log("EXERCISE 3:\n==========\n");
let coder = new Coder("personsName", 1, "placeOfResidence", ["hobby1", "hobby2", "hobby3"], "Full Stack Web Developer");
console.log(coder)
console.log(coder.greeting())
// Exercise 4 Section
console.log("EXERCISE 4:\n==========\n");
class Calculator {
add(a, b) {
let res;
if (b == undefined) {
res = this.result + a;
} else {
res = a + b;
}
this.result = res;
return this.result;
}
subtract(a, b) {
let res;
if (b == undefined) {
res = this.result - a;
} else {
res = a - b;
}
this.result = res;
return this.result;
}
multiply(a, b) {
let res;
if (b == undefined) {
res = this.result * a;
} else {
res = a * b;
}
this.result = res;
return this.result;
}
divide(a, b) {
let res;
if (b == undefined) {
res = this.result / a;
} else {
res = a / b;
}
this.result = res;
return this.result;
}
display() {
console.log(this.result);
}
}
let calc = new Calculator();
calc.add(1,1)
calc.subtract(1)
calc.multiply(10)
calc.divide(2)
calc.display();