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

284
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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