Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda