Search code examples
javascriptfreeboard

how to write if condition in javascript , if 1 it should show granted if 0 it should show denied


I'm using freeboard. I cloud platform where I'm adding my API and getting results in charts. I have an API which gives the values 1 and 0 but I need to show granted and denied instead of 1 and 0. There is an option to write is in the data sources like below

return datasources["rfid access"] + 3 // output coming 4 

like that i need to show granted if rfid access result is 1 and denied for 0


Solution

  • You can use simple logic like this:

    if(APIval === 0){
        return 'denied';
    }
    else{
        return 'granted';
    }
    

    Or you can use a conscise version of it:

    return APIval===0 ? 'denied' : 'granted';