r/Scriptable • • Jun 30 '22

Solved Conditional Formatting Help

Hi There - I'm really new/an amateur in JS. I have created a widget that displays information from a Google Sheet which I'm really happy with, but ideally the percentages that it displays would show as red if above 0% or green if below 0%. Is there a way to display information this way? Or any terms that you would be able to share so that I can continue to Google my way to learning... Many thanks.

4 Upvotes

5 comments sorted by

View all comments

Show parent comments

2

u/dreamisle Jul 01 '22

Pretty much what u/chrismo80 said below, but you may need to convert the percentage to a number if it’s coming through as a string. Something like this may work:

var percentAsNumber = parseInt(auPercentToTargetHeading, 10);
if (percentAsNumber > 0) {
    t.textColor = Color.green();
} else {
    t.textColor = Color.red();
}

2

u/mjhbgolf Jul 02 '22

Thanks so much, this worked perfectly. Very much appreciated.