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

249
Vistas
How can I change the value of a constructor key after it has been created?

I'm doing a simple constructor exercise and I need to change a value after the initial creation of the constructor. When I run it the cat is still not making its noise after I changed its value to true.

Challenge parameters

  • The constructor function will take in two parameters, raining and noise. These will be passed into the keys as their value.

  • Create a third key that will be a function called makeNoise(). The function checks if the raining key's value is true. If it is, it will log the value of the key's noise in the console.

Bonus

  • How can we make the cat make noise? In other words, how can we change the value of raining for the cat object after it has been created?
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 Respuestas
Responde la pregunta

0

You have to call makeNoise() after setting the raining property to true. When you call makeNoise() before, the raining property is false (since JS is (mostly) executed sequentially), so nothing is logged.

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 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