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

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

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