Playground - Jerarquía de animales
Clase 62 de 99 • 30 días de JavaScript
Contenido del curso
Clase 62 de 99 • 30 días de JavaScript
Contenido del curso
Pablo Pincay Alvarez
David Esteban Giraldo Duque
David Santiago Garcia Chicangana
Gustavo Alonso Aguilar Acuña
Osvaldo Martinez Guillen
Daniel Sebastián Rodríguez
HERNANDO RAMIREZ
Leonardo de los angeles Espinoza Hernandez
Gilberto Espinoza Maciel
Agustin Choque Veliz
Benjamin Rodriguez
Esteban Alzate Atehortua
Joan Alexander Valerio Rodríguez
Christopher Armando Jiménez Valverde
Jacobo Burbano
Harrison Steve Pinzón Neira
David Ochoa
Rubén Hernández Hernández
Pablo Perez
Pariksit Erikrsnan Ortiz Flores
Angel Javier Sanchez Tenjo
Carina Payleman
Jaime Alberto Parra Acevedo
Alejandro Anaya
Elias Rayas Gonzalez
SPOILERS
. . .
. . . . .
. .
Este ejercicio ha sido el mas "raro" Primero un error de tipeo creo en decir:
La clase base será Animal con las propiedades name, age y species y un método getInfo
cuando en los ejemplos y test esta "especie"
{ name: "pepe", age: 1, specie: "bird", }
luego en el test de Dog es raro, la parte del constructor, specie, siempre toma un valor unico que es "dog" y luego breed da undefined pero si cambias la posicion de breed en el lugar donde estaba especie,
breed toma el valor q esperan los test, a lo mejor es un error mio de compresion lectora, pero bueno.
mi codigo:
export class Animal { constructor(name, age, specie) { this.name = name; this.age = age; this.species = specie; } getInfo() { return { "name": this.name, "age": this.age, "specie": this.species } } } export class Mammal extends Animal { constructor(name, age, specie, hasFur) { super(name, age, specie); this.hasFur = hasFur; } getInfo() { const { name, age, specie } = super.getInfo() return { name, age, specie, "hasFur": this.hasFur } } } export class Dog extends Mammal { constructor(name, age, breed, hasFur) { super(name, age, "dog", hasFur); this.breed = breed; } getInfo() { const { name, age, specie, hasFur } = super.getInfo() return { name, age, specie, hasFur, "breed": this.breed } } bark() { return "woof!" } }
Me pasó lo mismo con lo de "specie" (creo que es un typo) y con los parámetros del constructor de la clase Dog
Opino lo mismo respecto al test que se realiza a Dog. La guía menciona que se debe agregar una propiedad adicional, en este caso, las de la clase Mammal. Sin embargo, al agregar esta propiedad para que sea recibida en el constructor de Dog y posteriormente asignarla a la respuesta de getInfo hace que no pase el test.
Al revisar la solución, se ve que no se envia un parametro mas para la clase Dog, solo se toma el valor que se enviaba normalmente en la posición de specie como el breed en esta ultima clase.
Mi aporte: Sigo insistiendo que el asincrotismo ha sido lo más dificil. . . . . . . . .
export class Animal { constructor(name, age, specie) { this.name = name; this.age = age; this.specie = specie; } getInfo() { return this } } export class Mammal extends Animal{ constructor(name, age, specie, hasFur) { super(name, age, specie); this.hasFur = hasFur; } getInfo() { return {...this, ...this.hasFur} } } export class Dog extends Mammal { constructor(name, age, breed, hasFur, specie="dog") { super(name, age, specie, hasFur); this.breed = breed; } getInfo() { return this } bark() { return "woof!" } }
Muy buena manera de usar el this. Me lo llevo como retroalimentación
Comparto la solución. Hay 2 problemas con el código
export class Animal { constructor(name, age, specie) { this._name = name this._age = age this._specie = specie } getInfo() { return {'name':this._name,'age':this._age,'specie':this._specie} } } export class Mammal extends Animal{ constructor(name, age, specie, hasFur) { super(name, age, specie) this._hasFur=hasFur } getInfo() { return Object.assign({},super.getInfo(),{'hasFur':this._hasFur}) } } export class Dog extends Mammal{ constructor(name, age, breed, hasFur) { super(name, age, "dog" ,hasFur) this._breed = breed } getInfo() { return Object.assign({}, super.getInfo(), {'breed': this._breed }) } bark() { return "woof!" } }
Gracias Daniel, con esto si pasa la prueba...
Gracias por este feedback Daniel! ya mismo lo corregimos 💪
Comparto mi solución porque el getInfo() lo resolví con una línea de código
.
.
.
.
.
.
.
.
.
export class Animal { // Tu código aquí 👈 constructor(name, age, specie) { this.name = name this.age = age this.specie = specie } getInfo() { return this } } export class Mammal extends Animal { // Tu código aquí 👈 constructor(name, age, specie, hasFur) { super(name, age, specie) this.hasFur = hasFur } getInfo() { return this } } export class Dog extends Mammal{ // Tu código aquí 👈 constructor(name, age, breed, hasFur) { super(name, age, "dog", hasFur) this.breed = breed } getInfo() { return this } bark() { return "woof!" } }
Aquí mi solución, y si, tienen razón, este ejercicio muy raro, el constructor de Dog con los parámetros en este orden constructor(name, age, hasFur, breed) no me funcionaba, pero después de cambiar el orden a: constructor(name, age, breed, hasFur), recién funcionó, debo decir que en la consola de Chrome funcionó normal, ¿alguien podría explicar eso?, creo que el Playground de Platzi debe pulirse un poco mas y por supuesto los enunciados, ya que siempre tienen errores.
export class Animal { constructor(name, age, specie) { this.name = name; this.age = age; this.specie = specie; } getInfo() { return this; } } export class Mammal extends Animal { constructor(name, age, specie, hasFur) { super(name, age, specie); this.hasFur = hasFur; } getInfo() { return this; } } export class Dog extends Mammal { constructor(name, age, breed, hasFur) { super(name, age, "dog", hasFur); this.breed = breed; } getInfo() { return this; } bark() { return "woof!"; } }
🛡️Escudo anti-spoilers🛡️
export class Animal { constructor(name, age, specie) { this.name = name this.age = age this.specie = specie } getInfo() { return { name: this.name, age: this.age, specie: this.specie, } } } export class Mammal extends Animal { constructor(name, age, specie, hasFur) { super(name, age, specie) this.hasFur = hasFur } getInfo() { const res = super.getInfo() return { ...res, hasFur: this.hasFur } } } export class Dog extends Mammal { constructor(name, age, breed, hasFur) { super(name, age, "dog", hasFur) this.breed = breed } getInfo() { const res = super.getInfo() return { ...res, breed: this.breed, } } bark() { return "woof!" } }
Mi solución . . . . . . . . . . . . .
export class Animal{ constructor(name,age,specie){ this.name=name; this.age=age; this.specie=specie; } getInfo(){ return this; } } export class Mammal extends Animal{ constructor(name,age,specie,hasFur){ super(name,age,specie); this.hasFur =hasFur; } getInfo(){ return this; } } export class Dog extends Mammal{ constructor(name,age,breed,hasFur,specie="dog"){ super(name,age,specie,hasFur); this.breed = breed; } getInfo(){ return this; } bark(){ return("woof!"); } }
Recomendación con mucho respeto y cariño para nuestro instructor, desde que inicie el curso hay un gran porcentaje de retos con una mala redacción y eso afecta mucho cuando estos ejercicios tienen que pasar por un test, donde lógicamente las respuestas ya están controladas. Este reto fue muy sencillo y se que muchos estarán de acuerdo conmigo, sin embargo, he perdido bastante tiempo en encontrar un error que se esta causando dentro mismo test. Tomen en cuenta que muchos evitamos ver los comentarios cuando estamos haciendo el ejercicio para evitar spoilers… vaya casualidad la mía, encontrarme con un gran numero de comentarios reportando un error en la clase Dog. Mi comentario lo hago con la intención de mejorar, tomen en cuenta que muchos ya tenemos experiencia en programación y tenemos paciencia cuando un error se presenta, pero puede llegar a ser muy frustrante para alguien nuevo. 😃 Mi comentario es porque no es el único ejercicio que me he encontrado en este curso con typos. Sugerencia -> debe haber alguien adicional que verifique todo antes de publicar el curso. 😃 Bueno nada tanto texto me ayudo para evitar spoilers… aunque siendo sinceros quizás en un caso como este conviene hacer el spoiler . Solución:
Buenas tardes, comparto mi solución:
export class Animal { constructor(name, age, specie) { this.name = name; this.age = age; this.specie = specie; } getInfo() { return this; } } export class Mammal extends Animal { constructor(name, age, specie, hasFur) { super(name, age, specie); this.hasFur = hasFur; } getInfo() { return this; } } export class Dog extends Mammal { constructor(name, age, breed, hasFur, specie = "dog" ) { super(name, age, specie, hasFur); this.breed = breed; } getInfo() { return this; } bark() { return "woof!"; } }
Creo que este ejercicio tiene demasiados fallos, me demore demasiado tiempo intentando encontrar la solucion de los errores que habia tenido y resultaba que eran errores sobre como estaba compuesto del ejercicio.
Desafio completado!
🛡️🛡️🛡️Escudo anti spoilers🛡️🛡️🛡️
Jerarquia de animales
!Spoiler Shield
export class Animal { // Tu código aquí 👈 constructor(name, age, specie) { this.name = name; this.age = age; this.specie = specie; } getInfo() { return { name: this.name, age: this.age, specie: this.specie, }; } } export class Mammal extends Animal { // Tu código aquí 👈 constructor(name, age, specie, hasFur) { super(name, age, specie); this.hasFur = hasFur; } getInfo() { return { ...super.getInfo(), hasFur: this.hasFur }; } } export class Dog extends Mammal { // Tu código aquí 👈 constructor(name, age, breed, hasFur) { super(name, age, "dog", hasFur); this.breed = breed; } getInfo() { return { ...super.getInfo(), breed: this.breed }; } bark() { return "woof!"; } }
Mi solución 💚 (realmente deberían de cambiar la redacción por los problemas en la varialbe specie y en cómo se define Dog.
!pug
.
.
.
export class Animal { constructor(name, age, specie) { this.name = name; this.age = age; this.specie = specie; } getInfo() { return { name: this.name, age: this.age, specie: this.specie } } } export class Mammal extends Animal { constructor(name, age, species, hasFur) { super(name, age, species); this.hasFur = hasFur; } getInfo() { return { ...super.getInfo(), hasFur: this.hasFur } } } export class Dog extends Mammal { constructor(name, age, breed, hasFur) { super(name, age, "dog", hasFur); this.breed = breed; } getInfo() { return { ... super.getInfo(), breed: this.breed, } } bark() { return "woof!" } }
export class Animal { constructor(name, age, specie) { this.name = name this.age = age this.specie = specie } getInfo() { return { name: this.name, age: this.age, specie: this.specie } } } export class Mammal extends Animal { constructor(name, age, specie, hasFur) { super(name, age, specie) this.hasFur = hasFur } getInfo() { const obj = super.getInfo() return { ...obj, hasFur: this.hasFur } } } export class Dog extends Mammal { constructor(name, age, breed, hasFur) { let specie = "dog" super(name, age, specie, hasFur) this.breed = breed } getInfo() { const obj = super.getInfo() return { ...obj, breed: this.breed } } bark() { return "woof!" } }
export class Animal { // Tu código aquí 👈 constructor(name, age, specie) { this.name = name; this.age = age; this.specie = specie; } getInfo() { return this; } } export class Mammal extends Animal{ // Tu código aquí 👈 constructor(name, age, specie, hasFur) { super(name, age, specie); this.hasFur = hasFur; } getInfo() { return { ...this, ...this.hasFur }; } } export class Dog extends Mammal{ // Tu código aquí 👈 constructor(name, age, breed, hasFur, specie = "dog") { super(name, age, specie, hasFur); this.breed = breed; } getInfo() { return { ...this, ...this.breed }; } bark() { return 'woof!'; } }
Hola, Comparto la solución al reto.
✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
export class Animal { constructor(name, age, specie) { this.name = name; this.age = age; this.specie = specie; } getInfo() { return this; } } export class Mammal extends Animal { constructor(name, age, specie, hasFur) { super(name, age, specie); this.hasFur = hasFur; } getInfo() { return this; } } export class Dog extends Mammal { constructor(name, age, breed, hasFur) { super(name, age, "dog", hasFur); this.breed = breed; } getInfo() { return this; } bark() { return "woof!"; } }
export class Animal { constructor(name, age, specie) { this.name = name; this.age = age; this.specie = specie; } getInfo() { return this; } } export class Mammal extends Animal { constructor(name, age, specie, hasFur) { super(name, age, specie); this.hasFur = hasFur; } getInfo() { return this; } } export class Dog extends Mammal { constructor(name, age, breed, hasFur, specie = "dog") { super(name, age, specie, hasFur); this.breed = breed; } getInfo() { return this; } bark() { return ("woof!"); } }
Esta es mi solución
export class Animal { constructor(name, age, specie) { this.name = name; this.age = age; this.specie = specie; } getInfo() { return { name: this.name, age: this.age, specie: this.specie } } } export class Mammal extends Animal { constructor(name, age, specie, hasFur) { super(name, age, specie) this.hasFur = hasFur; } getInfo() { return { name: this.name, age: this.age, specie: this.specie, hasFur: this.hasFur } } } export class Dog extends Mammal { constructor(name, age, breed, hasFur) { super(name, age, 'dog', hasFur) this.breed = breed; } getInfo() { return { name: this.name, age: this.age, specie: this.specie, hasFur: this.hasFur, breed: this.breed } } bark() { return "woof!"; } }
🛡️🛡️Escudo anti-spoilers🛡️🛡️
Mi solución al reto:
export class Animal { constructor(name, age, specie) { this.name = name; this.age = age; this.specie = specie; } getInfo() { return this } } export class Mammal extends Animal { constructor(name, age, specie, hasFur) { super(name, age, specie); this.hasFur = hasFur; } getInfo() { return { ...this, ...this.hasFur } } } export class Dog extends Mammal { //! Aqui la guia no ayuda nada bien, las pruebas unitarias estaban mal empleadas cambiando el orden de las propiedades constructor(name, age, breed, hasFur, specie = "dog") { super(name, age, specie, hasFur); this.breed = breed; } getInfo() { return this } bark() { return "woof!" } }
Solucion
class Animal { // Tu código aquí 👈 constructor(name, age, species) { this.name = name; this.age = age; this.species = species; } getInfo() { const info = { name: this.name, age: this.age, species: this.species, }; return info; } } class Mammal extends Animal{ // Tu código aquí 👈 constructor(name, age, species, hasFur) { super(name, age, species); this.hasFur = hasFur; } getInfo() { const mammalInfo = { ...super.getInfo(), hasFur: this.hasFur }; return mammalInfo } } class Dog extends Mammal{ // Tu código aquí 👈 constructor(name, age, breed, hasFur) { super(name, age, hasFur); this.breed = breed } bark() { return "Woof!" } }