-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.js
188 lines (178 loc) · 3.52 KB
/
classes.js
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
186
187
188
// class Person {
// constructor(name, age, eyes, hair){
// this.legs = 2;
// this.arms = 2;
// this.name = name;
// this.age = age;
// this.eyes = eyes;
// this.hair = hair;
// }
// setHair(hairColor){
// this.hair = hairColor;
// }
// greet(otherPerson){
// console.log('hi ' + otherPerson + '!');
// }
// jump(){
// console.log('weeee!');
// }
// };
//
// class SuperHero extends Person {
//
// };
// const me = new Person('Aaron', 36, 'brown', 'brown');
// me.setHair('Pink');
// console.log(me);
/// console.log(superman);
// class Person {
// constructor(name, age, eyes, hair) {
// this.legs = 2;
// this.arms = 2;
// this.name = name;
// this.age = age;
// this.eyes = eyes;
// this.hair = hair;
// }
// };
//
// class Pet {
// constructor(type, name, age, owner) {
// this.type = type;
// this.name = name;
// this.age = age;
// this.owner = owner;
// }
// };
//
// class Artist extends Person {
//
// }
//
// const cas = new Person ('Cas', 15, 'brown', 'brown')
// console.log(cas);
//
// class Robots {
// constructor(serial) {
// this.serial = serial;
// }
// };
//
// robotArr = [];
//
// const robotGenerator = () => {
// const newRobot = new Robots(robotArr.length);
// robotArr.push(newRobot);
// return newRobot;
// }
//
// console.log(robotGenerator());
// console.log(robotGenerator());
// console.log(robotGenerator());
// console.log(robotGenerator());
// console.log(robotArr);
class Pet {
constructor(name, owner) {
this.name = name;
this.owner = owner;
}
setOwner(owner){
this.owner = owner;
}
}
// const noodle = new Pet('Noodle')
// console.log(noodle);
// noodle.setOwner('Joni');
// console.log(noodle);
class Dog extends Pet {
constructor(name, price) {
super(name);
this.price = price;
}
bark(){
console.log('bark');
}
chaseTail(){
console.log('oh boy oh boy oh boy');
}
getPrice(){
return this.price;
}
}
// const sparky = new Dog('Sparky', 10)
// sparky.setOwner('Bandit');
// sparky.bark();
// sparky.chaseTail();
// sparky.getPrice();
// console.log(sparky);
class Cat extends Pet {
constructor(name, price) {
super(name);
this.price = price;
}
purr(){
console.log('purrrr');
}
clean(){
console.log('cleaning');
}
getPrice(){
return this.price;
}
}
const sprinkles = new Cat('Sprinkles', 5);
// sprinkles.setOwner('Crazy Cat Lady');
// sprinkles.purr();
// sprinkles.clean();
// sprinkles.getPrice();
// console.log(sprinkles);
class Person {
constructor(name){
this.name = name;
this.age = 0;
this.weight = 0;
this.mood = 0;
this.pets = [];
this.bankAccount = 0;
}
getName(){
return this.name;
}
getAge(){
return this.age;
}
getWeight(){
return this.weight;
}
greet(other_person){
console.log('Hi ' + other_person + '!');
}
eat(){
this.weight++;
this.mood++;
}
exercise(){
this.weight--;
}
birthday(){
this.age++;
this.weight++;
this.mood--;
this.bankAccount+=10;
}
buyPet(pet){
this.pets.push(pet);
this.mood+=10;
this.bankAccount = this.bankAccount - (pet.getPrice());
}
}
const aaron = new Person('Aaron');
console.log(aaron.getName());
console.log(aaron.getAge());
console.log(aaron.getWeight());
aaron.greet('Joni');
aaron.eat();
aaron.exercise();
aaron.birthday();
aaron.buyPet(sprinkles);
console.log(aaron);