If statement with button clicks

 $w('#appbutton11').onClick(()=>{
        if( $w('#apprepeater3').collapsed ){
        $w('#apprepeater1').collapse()
        $w('#apprepeater3').expand()
        }
        if( $w('#apprepeater1').collapsed ){
        $w('#apprepeater1').expand()
        $w('#apprepeater3').collapse()
        }

i really would like that a 1 button can do two different actions so i thought about the if statements .

is that the right way to do it ? , if so why it does not work where is the error here ?

$w.onReady(() => {
 $w('#appbutton11').onClick(() => {
        if( $w('#apprepeater3').collapsed ){
        $w('#apprepeater1').collapse()
        $w('#apprepeater3').expand()
        }
        if( $w('#apprepeater1').collapsed ){
        $w('#apprepeater1').expand()
        $w('#apprepeater3').collapse()
        }
})
})