Error in Javascript Code - satDiff and saturation cannot find

Hey,
i have an Error in my Javascript Code...
satDiff and saturation cannot find.
do i need to install anything else?

//These 3 lines boost the saturation, relative to how de-saturated a colour is
satDiff = 100 - msg.payload[1];
saturation = msg.payload[1] + (satDiff / 2);
//But don't let the saturation be > 100 else HA with throw an error
if (saturation > 100) { saturation = 100; }

//Construct a payload to send to the light using our values
msg.payload =
{
    "data":
    {
        "entity_id": "light.color_bulb",
        "brightness": "255",
        "hs_color": [msg.payload[0], saturation]
    }
}
return msg;

You need to declare the first use of a var
with const, let or var, to remove the errors.

let satDiff = 100 - msg.payload[1];
let saturation = msg.payload[1] + (satDiff / 2);
1 Like

What do you see if you click "quick fix"?

Bildschirmfoto 2023-06-05 um 06.11.03

that looks better!

what just surprises me:
I still have an "old" container running with NodeRED. Since I only had chaos there, I created a new CT.
In the old container, however, this function node is displayed "correctly".
and there I had taken over the code one to one.

The code you have does not actually have an error, but it is now considered bad practice to allow undeclared variables, as it can easily lead to bugs. The code checker in newer versions of node red is more strict than in older versions.

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