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

283
Views
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 answers
Answer question

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 Report

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