# Error in Javascript Code - satDiff and saturation cannot find

**URL:** https://discourse.nodered.org/t/error-in-javascript-code-satdiff-and-saturation-cannot-find/78941
**Category:** General
**Created:** [4 June 2023 20:44 UTC](https://discourse.nodered.org/t/error-in-javascript-code-satdiff-and-saturation-cannot-find/78941 "2023-06-04T20:44:13Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![MrThiemann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrthiemann/32/68063_2.png) [@MrThiemann](https://discourse.nodered.org/u/MrThiemann)
#### Post date: [4 June 2023 20:44 UTC](https://discourse.nodered.org/t/error-in-javascript-code-satdiff-and-saturation-cannot-find/78941/1 "2023-06-04T20:44:13Z")

</div>

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

 ![Bildschirmfoto 2023-06-04 um 22.38.52](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/1/e1485b00922c9fe5d4d6a554b5638a526934d921.png)

```auto
//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;

```

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [4 June 2023 21:09 UTC](https://discourse.nodered.org/t/error-in-javascript-code-satdiff-and-saturation-cannot-find/78941/2 "2023-06-04T21:09:27Z")

</div>

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

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

```

---

<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: [4 June 2023 22:20 UTC](https://discourse.nodered.org/t/error-in-javascript-code-satdiff-and-saturation-cannot-find/78941/3 "2023-06-04T22:20:08Z")

</div>

> [@MrThiemann](#):
>
> ![Bildschirmfoto 2023-06-04 um 22.38.52](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/1/e1485b00922c9fe5d4d6a554b5638a526934d921.png)

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

---

<div class="post-metadata">

### Author: ![MrThiemann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrthiemann/32/68063_2.png) [@MrThiemann](https://discourse.nodered.org/u/MrThiemann)
#### Post date: [5 June 2023 04:12 UTC](https://discourse.nodered.org/t/error-in-javascript-code-satdiff-and-saturation-cannot-find/78941/4 "2023-06-05T04:12:19Z")

</div>

![Bildschirmfoto 2023-06-05 um 06.11.03](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/6/3637451acdcd8ec11256504ed18d9674b31e4364.png)

---

<div class="post-metadata">

### Author: ![MrThiemann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrthiemann/32/68063_2.png) [@MrThiemann](https://discourse.nodered.org/u/MrThiemann)
#### Post date: [5 June 2023 04:14 UTC](https://discourse.nodered.org/t/error-in-javascript-code-satdiff-and-saturation-cannot-find/78941/5 "2023-06-05T04:14:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [5 June 2023 07:13 UTC](https://discourse.nodered.org/t/error-in-javascript-code-satdiff-and-saturation-cannot-find/78941/6 "2023-06-05T07:13:30Z")

</div>

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.

---

<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: [4 August 2023 07:14 UTC](https://discourse.nodered.org/t/error-in-javascript-code-satdiff-and-saturation-cannot-find/78941/7 "2023-08-04T07:14:04Z")

</div>

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