forked from su-ntu-ctp/6m-software-entry-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq4.js
30 lines (25 loc) · 877 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
/*
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) in the Child class 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
const c = new Child();
c.addNewAbility("Dancing");
c.showAbilities(); // This function should print "Parenting", "Role modeling" and "Dancing".