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

287
Visualizações
Checkbox checked property got ruined by the conditionals?

a beginner coder here (and also my first post). I was trying to make function that will change the value of a previously defined variable when the checkbox is checked or unchecked. I tried to write this code to see if the checked property of my checkbox is working.

function calc5() {
  var check5Object = document.getElementById("check5");
  stat5 = check5Object.checked;
  console.log(stat5);
}

When i checked the console, it works out like expected. When the checkbox is checked it logs true and when the checkbox is unchecked it logs false on the console like this. I thought it was working smoothly... until i added the conditionals. The code looks like this:

function calc5() {
  var check5Object = document.getElementById("check5");
  stat5 = check5Object.checked;
  if ((stat5 = true)) {
    bobux5 = 10000;
  } else {
    bobux5 = 0;
  }
  console.log(stat5);
}

And the result on the console looks like this

Everytime I click the checkbox, it just logs as "true" all the time. Can someone help me figure it out what went wrong in my code? It will be very helpful! (btw im making a robux "scam" website that will rickroll you at the end, its harmless)

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You need to use == and rather use =

From:

if (stat5 = true) {
    bobux5 = 10000;
}

to:

if (stat5 == true) {
    bobux5 = 10000;
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Use this code:

function calc5() {
  var check5Object = document.getElementById("check5");
  var bobux5 = 0;
  stat5 = check5Object.checked;
  if (stat5 == true) {
    bobux5 = 10000;
  }
  console.log(stat5);
}

in fact you should use == in conditions. => (if == X TURE) and (if = X FALSE)

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