Switch event to change other switch states

I’m trying to setup a page where if one switch changes state, it causes another switch to change its state. Here is the code I posted into the page code

export function switch2_change(event) {
$w(“#switch1”).checked = false ;
}

For example, lets say switch 1 is true (i.e. graphically slid to the right). When I change the state of switch 2 by clicking on it, it should set switch 1 false (i.e. graphically slid to the right). I can’t figure out what I’m doing wrong.

Hey there!
Your code is not wrong but you do not check the value of the switch2 so it will always set the switch1 to false.

export function switch2_change(event) {
          if ($w("#switch2").checked) {
            $w("#switch1").checked = false;
          } else {
            $w("#switch1").checked = true;
          }       
}

Hope that helps!

API Reference for Switch: