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
42 lines (38 loc) · 1.16 KB
/
app.js
File metadata and controls
42 lines (38 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
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() {
return console.log(
`Name: ${this.name} Pets: ${this.pets} Residence: ${this.residence} Hobbies: ${this.hobbies}`
);
}
greeting() {
return console.log(
`Hello! My name is ${this.name}. I have ${this.pets} pets. I live in ${this.residence} and like ${this.hobbies}.`
);
}
}
let person = new Person("Bob", 2, "New York", ["coding, cooking, gaming"]);
person.info();
person.greeting();
class Coder extends Person {
constructor(name, pets, residence, hobbies) {
super(name, pets, residence, hobbies);
this.occupation = "Full Stack Web Developer";
}
greeting() {
return console.log(
`Hello! My name is ${this.name}. I'm a ${this.occupation}. I have ${this.pets} pets. I live in ${this.residence} and like ${this.hobbies}.`
);
}
}
const kevin = new Coder("Kevin", 0, "New Jersey", ["coding, gaming"]);
kevin.info();
kevin.greeting();