How can I only have one checkbox checked at a time

Hello! I’m trying to make 4 checkboxes be connected in a way that only one of them can be checked at a time. I found some lines of code from 2018 regarding this problem, but it doesn’t seem to wanna work for me. This is what I tried to use:

$w.onReady(function () {
 for (let i = 1; i < 4; i++) {
        $w(`#checkbox${i}`).onChange(() => {
 const checkBoxes = ['#checkbox4', '#checkbox3', '#checkbox2', '#checkbox5'];
 let filtered = checkBoxes.filter(item => item !== `checkbox${i}`);
            filtered.forEach((checkbox) => {
                $w(`#${checkbox}`).checked = false;
            });
        });
    }
});

Did I do anything wrong here or is there another way you guys can suggest to make this possible?

Thank you in advance.

$w.onReady(function () {
   $w('Checkbox').onChange((event) => {
   let elementID = event.target.id
   
   deactivate_allCheckboxes()
   .then(()=>{
      $w('#'+elementID).checked = true;
   })
});

function deactivate_allCheckboxes() {
   $w('#checkbox2).checked = false;
   $w('#checkbox3').checked = false;
   $w('#checkbox4').checked = false;
   $w('#checkbox4').checked = false;
}

Of course you can LOOP the “deactivate_allCheckboxes”-function and improve this code.

It is just an quick and simple example.

The last bracket at the bottom seems to keep getting highlighted and the system keeps saying “Parsing error: Unexpected token”. Any idea why that is happening?

Yes, i forgot to set one more → }) before the function.
This should fix the problem.

Thank you. This helped me a lot.

No problem.