Not working variables

Do anyone know why the variable “Canje” is changed in the query, but when I click the button 12, the value Canje looks like it doesnt exist?

import wixLocation from 'wix-location'
import wixData from 'wix-data'

var Canje = 0;

$w.onReady(function () {
 wixData.query("Vales").contains('dni', $w('#input14').value)
  .count()
  .then( (num) => {
 Canje = num;
 $w('#input19').value = Canje
  } )
  .catch( (error) => {
 let errorMsg = error.message;
 let code = error.code;
  } )
});

export async function button12_Click() {
 Here it runs more code but its not necessary for the explanation
 if ( Canje === '0'||Canje <'0') {
 $w('#button14').enable()
    }
 if (Canje >'0') {
 $w('#button14').disable()
 $w('#button15').disable()
 $w('#button14').label = "VALE YA CANJEADO"
    }

}

Perhaps this one…

import wixLocation from 'wix-location'
import wixData from 'wix-data'

var Canje = 0;

$w.onReady(function () {
    wixData.query("Vales").contains('dni', $w('#input14').value)
    .count()
    .then((num) => {
        Canje = num;
        console.log(Canje)
        console.log(typeof Canje)
        $w('#input19').value = Canje
    })
    .catch( (error) => {
        let errorMsg = error.message;
        let code = error.code;
    });

    $w('#button12').onClick(()=>{
        if ( Canje === '0'||Canje <'0') {// ---> if (Canje <= 0)
            $w('#button14').enable()
        }
        else{console.log("Else-part running")
            $w('#button14').disable()
            $w('#button15').disable()
            $w('#button14').label = "VALE YA CANJEADO"
        }
    });
});

Check also the results in the CONSOLE.
Your problem will surely be that you are mixing between STRING and NUMBER.

Thank you so much, it was a problem with string and number :sweat:

@alejandroiriz01 :wink: