-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathninja.js
More file actions
45 lines (38 loc) · 959 Bytes
/
ninja.js
File metadata and controls
45 lines (38 loc) · 959 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
42
43
44
45
class Ninja {
constructor(name, health) {
this.name = name;
this.health = health;
this.speed = 3;
this.strength = 3;
}
sayName(){
console.log("Name: " + this.name);
}
showStats(){
console.log("Name: " + this.name);
console.log("Speed: " + this.speed);
console.log("Strength: " + this.strength);
console.log("Health: " + this.health);
}
drinkSake (){
this.health += 10;
}
}
class Sensei extends Ninja {
constructor(name) {
super(name,200);
this.speed = 10;
this.strength = 10;
this.wisdom = 10;
}
speakWisdom(){
console.log("You only live once");
super.drinkSake();
}
}
// ejemplo de salida
const superSensei = new Sensei("Master Splinter");
superSensei.speakWisdom();
// -> "Lo que un programador puede hacer en un mes, dos programadores pueden hacerlo en dos meses."
superSensei.showStats();
// -> "Nombre: Master Splinter, Salud: 210, Velocidad: 10, Fuerza: 10"