# Error in function case

**URL:** <https://discourse.nodered.org/t/error-in-function-case/77195>\
**Category:** General\
**Created:** [3 April 2023 11:35 UTC](https://discourse.nodered.org/t/error-in-function-case/77195 "2023-04-03T11:35:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [3 April 2023 11:35 UTC](https://discourse.nodered.org/t/error-in-function-case/77195/1 "2023-04-03T11:35:20Z")

</div>

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

**windCardinal is a const var**

 ![error](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/671bdbb73e7c549fa68ada2de9e40e581dad7b85.png)

```auto
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 .....

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [3 April 2023 11:49 UTC](https://discourse.nodered.org/t/error-in-function-case/77195/2 "2023-04-03T11:49:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 April 2023 11:56 UTC](https://discourse.nodered.org/t/error-in-function-case/77195/3 "2023-04-03T11:56:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [3 April 2023 12:09 UTC](https://discourse.nodered.org/t/error-in-function-case/77195/4 "2023-04-03T12:09:11Z")

</div>

Well I fix the problem ....

The var windCardinal derives from this function:

```auto
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 .....

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 April 2023 12:21 UTC](https://discourse.nodered.org/t/error-in-function-case/77195/5 "2023-04-03T12:21:21Z")

</div>

> [@Giamma](#):
>
> The var windCardinal derives from this function:

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

Like I said ↓

> [@Steve-Mcl](#):
>
> or set in your code above to every value except "O", "SO" & "NO" - therefore complaining because the values "O", "SO" & "NO" are impossible & pointless.

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

---

<div class="post-metadata">

**Author:** ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)\
**Post date:** [3 April 2023 12:23 UTC](https://discourse.nodered.org/t/error-in-function-case/77195/6 "2023-04-03T12:23:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [2 June 2023 12:24 UTC](https://discourse.nodered.org/t/error-in-function-case/77195/7 "2023-06-02T12:24:02Z")

</div>

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