Error in function case

Hi,
I don't understand where is the error ...
Can you help me?

windCardinal is a const var

if (windSpeed > 2) 
{
    switch (windCardinal) 
    {
        case "NE":
            output[8] = { label: "GRECALE" }
            break;
        case "N":
            output[8] = { label: "TRAMONTANA" }
            break;
        case "E":
            output[8] = { label: "LEVANTE" }
            break;
        case "SE":
            output[8] = { label: "SCIROCCO" }
            break;
        case "S":
            output[8] = { label: "OSTRO" }
            break;
        case "O":
            output[8] = { label: "PONENTE" }
            break;
        case "SO":
            output[8] = { label: "LIBECCIO" }
            break;
        case "NO":
            output[8] = { label: "MAESTRALE" }
            break;
        default:
            output[8] = { label: "-" }
    }
}
else 
{
    output[8] = { label: "-" }
}

If I delete case "O", "SO", "NO" I have no error .....

What does the editor show when you put the cursor over "O" ?

What else is in the function (that looks like a fragment and as it stands, there is no error - but other parts of the function may shed some light)

My guess would be windCardinal is a typed variable or set in your code above to every value except "O", "SO" & "NO" - therefore complaining because the values "O", "SO" & "NO" are impossible & pointless.

Well I fix the problem ....

The var windCardinal derives from this function:

let degreesToCardinal = function (deg) {
    if (deg > 11.25 && deg <= 33.75) { return "NNE"; }
    else if (deg > 33.75 && deg < 56.25) { return "NE"; }
    else if (deg > 56.25 && deg < 78.75) { return "ENE"; }
    else if (deg > 78.75 && deg < 101.25) { return "E"; }
    else if (deg > 101.25 && deg < 123.75) { return "ESE"; }
    else if (deg > 123.75 && deg < 146.25) { return "SE"; }
    else if (deg > 146.25 && deg < 168.75) { return "SSE"; }
    else if (deg > 168.75 && deg < 191.25) { return "S"; }
    else if (deg > 191.25 && deg < 213.75) { return "SSW"; }
    else if (deg > 213.75 && deg < 236.25) { return "SW"; }
    else if (deg > 236.25 && deg < 258.75) { return "WSW"; }
    else if (deg > 258.75 && deg < 281.25) { return "W"; }
    else if (deg > 281.25 && deg < 303.75) { return "WNW"; }
    else if (deg > 303.75 && deg < 326.25) { return "NW"; }
    else if (deg > 326.25 && deg < 348.75) { return "NNW"; }
    else { return "N"; }
}

const windSpeed = Number(msg.payload.current.wind_speed.toFixed(1));
const windCardinal = degreesToCardinal(msg.payload.current.wind_deg);

and case "O", "SO", "NO" are not in that list.

Sorry, I am no longer young and sometimes I lose myself .....

So the Function Node Editor KNOWS that the function will never return "O", "SO" or "NO"

Like I said ↓

So how did you fix this. Did you add "O", "SO" & "NO" as possible return values OR did you remove "O", "SO" & "NO" cases?

I replace "O" with "W" in the case selection

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.