Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
¿Cómo puedo cambiar el valor de una clave de constructor después de haberla creado?

Estoy haciendo un ejercicio de constructor simple y necesito cambiar un valor después de la creación inicial del constructor. Cuando lo ejecuto, el gato todavía no hace ruido después de que cambié su valor a verdadero.

Parámetros del desafío

  • La función constructora tomará dos parámetros, raining y noise . Estos se pasarán a las claves como su valor.

  • Cree una tercera clave que será una función llamada makeNoise() . La función comprueba si el valor de la clave de raining es true . Si es así, registrará el valor del noise de la tecla en la consola.

Prima

  • ¿Cómo podemos hacer que el gato haga ruido? En otras palabras, ¿cómo podemos cambiar el valor de raining para el objeto cat después de haberlo creado?
 function Animal(raining, noise) { this.raining = raining, this.noise = noise; this.makeNoise = function(){ if(this.raining) console.log(noise) } } // Creates `dog` and `cat` objects with `raining` and `noise` properties let dog = new Animal(true, 'Woof!'); let cat = new Animal(false, 'Meow!'); // Calls the `makeNoise()` methods on the `dog` and `cat` objects dog.makeNoise(); cat.makeNoise(); // BONUS CODE HERE cat.raining= true;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe llamar a makeNoise() después de establecer la propiedad raining en true . Cuando llama a makeNoise() antes, la propiedad raining es false (ya que JS se ejecuta (principalmente) secuencialmente), por lo que no se registra nada.

 function Animal(raining, noise) { this.raining = raining, this.noise = noise; this.makeNoise = function() { if (this.raining) console.log(noise) } } // Creates `dog` and `cat` objects with `raining` and `noise` properties let dog = new Animal(true, 'Woof!'); let cat = new Animal(false, 'Meow!'); // Calls the `makeNoise()` methods on the `dog` and `cat` objects dog.makeNoise(); cat.makeNoise(); // BONUS CODE HERE cat.raining = true; cat.makeNoise();

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!