-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass.js
66 lines (45 loc) · 1.11 KB
/
Class.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
class Animal {
constructor(name, breed) {
this.name = name;
this.breed = breed;
}
describe() {
console.log("This is the name of the animal: " + this.name);
}
}
class Dog extends Animal {
constructor(name, breed) {
super(name, breed);
}
describe() {
super.describe();
console.log("It is a dog");
}
}
const newDog = new Dog("Suzie", "Labrador");
newDog.describe();
class Todo {
constructor(title, description) {
this.title = title;
this.description = description;
this.completed = false;
}
markAsCompleted() {
this.completed = true;
}
markAsIncomplete() {
this.completed = false;
}
describe() {
console.log(`Title: ${this.title}`);
console.log(`Description: ${this.description}`);
console.log(`Completed: ${this.completed ? 'Yes' : 'No'}`);
}
}
const todo1 = new Todo("Learn JavaScript", "Complete a JavaScript tutorial");
const todo2 = new Todo("Write an article", "Write an article on JavaScript");
todo1.describe();
todo2.describe();
todo1.markAsCompleted();
console.log("\nAfter marking as completed:");
todo1.describe();