Solución

@estouchedisindo·9/5/2026TypeScript
solution.tsTypeScript
export function makeSound(type: 'dog' | 'cat', name: string): string {
  // Crea la instancia correspondiente y retorna la descripción del sonido
  class Animal {
    name = '';
    constructor(name: string) {
      this.name = name;
    }

    sound() {
      return '...';
    }
  }

  class Dog extends Animal {
    override sound() {
      return 'Guau'
    }
  }

  class Cat extends Animal {
    override sound() {
      return 'Miau'
    }
  }

  let whatAnimalSays = '';

  if(type === 'dog') {
    const newDog = new Dog(name);
    whatAnimalSays = `${name} dice ${newDog.sound()}`;
  }

  if(type === 'cat') {
    const newCat = new Cat(name);
    whatAnimalSays = `${name} dice ${newCat.sound()}` 
  }

  return whatAnimalSays;
}
0respuestas
Respuestas

Aún no hay respuestas

¡Sé el primero en responder!

Escribir un comentario

Recuerda ser amable. Estás comentando la solución de otra persona. Comparte tu perspectiva de forma constructiva y respetuosa.

Debes iniciar sesión para publicar un comentario.