Skip to content

Commit dce645a

Browse files
committed
#9 - JavaScript
1 parent ede512c commit dce645a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
class Animal {
2+
3+
constructor(nombre) {
4+
this.nombre = nombre
5+
}
6+
7+
sonido() {
8+
return `${this.nombre} hace un sonido.`
9+
}
10+
}
11+
12+
class Perro extends Animal {
13+
14+
constructor(nombre) {
15+
super(nombre)
16+
}
17+
18+
sonido() {
19+
return `${this.nombre} ladra: ¡Guau guau!`
20+
}
21+
22+
}
23+
24+
class Gato extends Animal {
25+
26+
constructor(nombre) {
27+
super(nombre)
28+
}
29+
30+
sonido() {
31+
return `${this.nombre} maúlla: ¡Miau miau!`
32+
}
33+
34+
}
35+
36+
function imprimirSonido(animal) {
37+
return animal.sonido();
38+
}
39+
40+
const miPerro = new Perro("Rex")
41+
const miGato = new Gato("Mimi")
42+
43+
console.log(imprimirSonido(miPerro))
44+
console.log(imprimirSonido(miGato))

0 commit comments

Comments
 (0)