Why does this simple ternary always return the "true" value even when false?


#1

I’m trying to create a nested ternary to perform different actions if the response from “$twcweather.conditions.cloudCoverPhrase” is Clear, Partly Cloudy, Mostly Cloudy, or Cloudy, but I can’t even get the basic ternary to function.

When I try to set up the simple ternary:
($twcweather.conditions.cloudCoverPhrase=“Clear”?“yes”:“no”)

It always returns “yes”, regardless of the actual value reported by $twcweather.conditions.cloudCoverPhrase (tonight it’s “Cloudy”, but still reports “yes”)

This is driving me bonkers! Any idea what I’m missing?


#2

I am not sure if it matters, but I notice you are using opening and closing parenthesis.

This works for me:

You can also stack them like this (Currently Cloudy):


#3

I don’t think “contains” will work because I have “cloudy” contained in all of “cloudy”, “partly cloudy” and “mostly cloudy”. The parentheses I think are just added when I copy/paste here; just typed straight into webCoRE without any funny business.


#4

If you want to differentiate between partly cloudy, mostly cloudy and just plain cloudy, the above method still works. (you can have more than one word in between apostrophes)


Some keyboard try to be “helpful” by turning parenthesis into opening and closing… Even with only one button pressed. (typically seen when coding on a cell phone)


#5

Hmm… I suppose I could just use the terms “clear”, “partly”, “mostly”. Worth a shot!


#6

Well, careful though because a few descriptors begin with Mostly and/or Partly


#7

From the looks of things here: https://wiki.webcore.co/TWC_Weather
The only options for $twcweather.conditions. cloudCover Phrase are "“Clear”, “Partly Cloudy”, “Mostly Cloudy”, “Cloudy”

Still don’t know why the original ternary doesn’t work.


#8

Use ==


#9

Here it is without the CONTAINS:

temp

eq stands for equal. More examples can be found here.


#10

Fantastic! Thanks for that!


#11

Here shows that Cloud will not match Cloudy:

temp


#12

Awesome. Got it set up with this:

(eq($twcweather.conditions.cloudCoverPhrase,'Clear') ? 1 : eq($twcweather.conditions.cloudCoverPhrase,'Partly') ? 0.98 eq($twcweather.conditions.cloudCoverPhrase,'Mostly') ? 0.965 : 0.95)

#13

You are missing a colon there before an eq

eq($twcweather.conditions.cloudCoverPhrase,‘Clear’) ? 1 :
eq($twcweather.conditions.cloudCoverPhrase,‘Partly’) ? 0.98 :
eq($twcweather.conditions.cloudCoverPhrase,‘Mostly’) ? 0.965 : 0.95


#14

Good catch! You’ve been a lot of help, WCmore.


#15

Glad to be able to! This is such an awesome community here!!


#16

Pro Tip for future reference:

If you code in an ‘Expression’ box, you can add new lines to make the code easier to work with. Like this:

temp


#17

Do you mean that you can “return” down without breaking the code? Good to know!


#18

Yes. it is almost like html where carriage returns are ignored


#19

I just saw your earlier comment. Unfortunately, I have not been able to find a document showing a full list of available responses in the new $twcweather. So far, we have been adding to the wiki as we notice new data coming in for our location. (as always, the wiki is a work in progress)


#20

ok, well they look to be “cloudCover” type responses, and those options give me the granularity I need. Thanks for the update!