-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq4.js
38 lines (33 loc) · 1011 Bytes
/
q4.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
/*
Task 1:
- Implement a Child class that extends the Parent.
- Add a constructor to the Child class can calls super().
- Implement a new function addNewAbilities(newAbility) where the new ability will be added to the Parent's #abilities array.
*/
class Parent{
abilities = []
constructor(){
this.abilities.push("Parenting");
this.abilities.push("Role modeling");
}
showAbilities(){
console.log("These are the abilities:")
for(const a of this.abilities){
console.log(a);
}
}
}
const p = new Parent();
p.showAbilities(); // Observe that this function prints "Parenting" and "Role modeling".
// Task 1: Add code here
class Child extends Parent {
constructor() {
super();
}
addNewAbility(newAbility){
this.abilities.push(newAbility);
}
}
const c = new Child();
c.addNewAbility("Dancing");
c.showAbilities(); // This function should print "Parenting", "Role modeling" and "Dancing".