Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

177
Vistas
I am wanting to print the properties of this class, all is well until I see that when I show the AddPet() method in the console

it shows me that I have the value 'perro' that I pass to the object and a value that is undefined when I did not requested it in any other side, what is the cause of this error?

class Usuario {
  constructor(nombre, apellido, libros, mascotas) {
    this.nombre = nombre;
    this.apellido = apellido;
    this.libros = libros;
    this.mascotas = mascotas;
  }

  getFullName() {
    console.log(`${this.nombre} ${this.apellido}`);
  }

  addMascota(mascota) {
    this.mascotas.push(mascota);
  }

  countMascotas() {
    return this.mascotas.length;
  }

  addBook(nombre, autor) {
    this.libros.push(nombre, autor);
  }

  static definicion() {
    console.log("Una persona es un ser humano!");
  }
}

const usuario = new Usuario(
  "John",
  "Doe", [{
    nombre: "El señor de los anillos",
    autor: "J.R.R. Tolkien"
  }], ['perro']
);

usuario.getFullName();
usuario.addMascota();
usuario.countMascotas();

console.log(usuario);

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You don't seem to have added an argument into addMascota() In the initiation you have this.mascotas set to ["perro"], so without having an argument for addMascota() it will add undefined to the list, resulting in ["perro", undefined] hopefully this helped :)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda