forked from bloominstituteoftechnology/JavaScript-II-Mini
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.js
More file actions
42 lines (34 loc) · 923 Bytes
/
classes.js
File metadata and controls
42 lines (34 loc) · 923 Bytes
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
// to test these problems you can run 'node classes.js' in your terminal
// problem #1
// convert the Animal constructor function from 'constructors.js' into an ES6 class
// function Animal(options) {
// this.name = options.name;
// }
// // add 'grow' to Animal's prototype here
// Animal.prototype.grow = function () {
// return `${this.name} grew larger!`;
// };
class Animal {
constructor(options) {
this.name = options.name;
}
grow() {
console.log(`${this.name} grew larger!`);
}
}
// problem #2
// convert the Cat constructor function from 'constructors.js' into an ES6 class
class Cat extends Animal {
super() {
super.grow();
}
meow() {
console.log(`${this.name} meowed!`);
}
}
// if everything is setup properly the code below will print 'Foofie grew larger!'
// uncomment the code below to test your solution
const foofie = new Cat({
name: 'foofie',
});
foofie.grow();