# Diff between values

**URL:** <https://discourse.nodered.org/t/diff-between-values/43035>\
**Category:** General\
**Created:** [22 March 2021 18:55 UTC](https://discourse.nodered.org/t/diff-between-values/43035 "2021-03-22T18:55:39Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [22 March 2021 21:53 UTC](https://discourse.nodered.org/t/diff-between-values/43035/5 "2021-03-22T21:53:27Z")

</div>

put node.warn() in the code to understand what is going on...

```auto
var TempD = flow.get("Temp-Diff") || 0;
node.warn("TempD = " + TempD);
if (TempD>8) {
  node.warn("TempD is > 8, setting msg.payload= 'on'");
  msg.payload='on'
} else if (TempD<=8) {
  node.warn("TempD is <= 8, setting msg.payload= 'off'");
  msg.payload='off'
}
return msg;

```

* * *

You really should read up...

> [@Steve-Mcl](#):
>
> Also, have a read of [Writing Functions : Node-RED](https://nodered.org/docs/user-guide/writing-functions#context)

---

_[View the full topic](https://discourse.nodered.org/t/diff-between-values/43035)._
