It’s always helpful if you post a link to the thing you are working on, because it can be hard in the plain text to see what’s working or not. Like I wasn’t clear if your issue was that you left off rgb from the color functions, or if there is a missing {} from the conditional, etc.
There are a few ways to do this. Looks like you were trying to get to Method 1, but didn’t quite have the conditional syntax correct. I like the second method because it will leave your color palette less cluttered.