# Ternary operator logic help please [SOLVED]

I’m struggling with a nested ternary operator for some time now. Just can’t seem to get it right.

The condition would be to change the opacity of an element depending on times of certain days.

Every day: between 10pm and 6am → 100
Sunday and Wednesday: between 6am and 6pm → 0 (I only use the condition until 6pm because the first condition already covers before 6am)
Monday and Thursday: between 6pm and 10pm → 0 (I only use the condition until 6pm because the first condition already covers after 10pm)
Every other occasions → 100

Here’s a code and also simulated with if-then. What am I missing?

`((([HOUR_1_24]>21)+([HOUR_1_24]<6)?100):((([DAY_WEEK]==1)+([DAY_WEEK]==4)*([HOUR_1_24]<18)?0):(([DAY_WEEK]==2)+([DAY_WEEK]==5)*([HOUR_1_24]>17)?0):100))`

I think I figured it out!

`(([HOUR_1_24]>21)+([HOUR_1_24]<6)?100:((([DAY_WEEK]==1)+([DAY_WEEK]==4))*([HOUR_1_24]<18))?0:((([DAY_WEEK]==2)+([DAY_WEEK]==5))*([HOUR_1_24]>17)?0:100))`

Thanks for the solution.

A trick I do is write each condition on a separate line in Notepad

Like
(
([HOUR_1_24]>21)+([HOUR_1_24]<6)
?
100:
(
(
([DAY_WEEK]==1)
+([DAY_WEEK]==4)
)*

it helps me organize it better like your if else does. When you paste into the WFS text box it removes all the new lines and looks like one big line.

Ron
Samsung Developer Relatins

Yeah, I did the same at the end when it got super complicated, but didn’t know I could just copy from Notepad, thanks for the tip.

I also used a different code editor which highlights the relations of the brackets. That helped as well to visualize easier.

Wouldn’t it be nice to have a bigger editor window with some visual aids in WFS? I think so.
I suggested that they include a text file for notes and comments. Perhaps one of the code editor would be something even better but I think that is beyond the scope.

Ron
Samsung Developer Relations

Ron