# Two simple bits of code can't coexist together - I'm clearly doing something stupid

**URL:** <https://discourse.nodered.org/t/two-simple-bits-of-code-cant-coexist-together-im-clearly-doing-something-stupid/42143>\
**Category:** General\
**Created:** [6 March 2021 11:12 UTC](https://discourse.nodered.org/t/two-simple-bits-of-code-cant-coexist-together-im-clearly-doing-something-stupid/42143 "2021-03-06T11:12:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dclear](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dclear/32/9107_2.png) [@dclear](https://discourse.nodered.org/u/dclear)\
**Post date:** [6 March 2021 11:12 UTC](https://discourse.nodered.org/t/two-simple-bits-of-code-cant-coexist-together-im-clearly-doing-something-stupid/42143/1 "2021-03-06T11:12:28Z")

</div>

```auto
//const shiftstart = msg.payload.shift_start.timestamp;
//const clockin = msg.payload.clockin_time.timestamp;
//const timeDifference = shiftstart - clockin;
//const timeDifference2 = clockin - shiftstart;
var breakd = msg.payload.duration
breakd = breakd.replace('m',"");
breakd = Number(breakd);
msg.payload.woo2 = breakd;
// if ((timeDifference/60).toFixed(0) >= 3){
// msg.payload = msg.payload.name +" was " + (timeDifference/60).toFixed(0) + " minutes early today";
// } else if ((timeDifference/60).toFixed(0) < 3){
// msg.payload = msg.payload.name +" was " + (timeDifference2/60).toFixed(0) + " minutes late today";
// }
  if (breakd < 25) { msg.payload.woo = "over 25"}
    else {msg.payload.woo = "under 25"}  
return msg;

```

If I remove the comment slashes, `msg.payload.woo2` goes 'undefined' - if I keep them in, I get a number.

Confusing what about the commented out code is somehow overwriting `msg.payload.woo2`

Anyone know?! Thanks

---

<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:** [6 March 2021 11:17 UTC](https://discourse.nodered.org/t/two-simple-bits-of-code-cant-coexist-together-im-clearly-doing-something-stupid/42143/2 "2021-03-06T11:17:48Z")

</div>

> [@dclear](#):
>
> Confusing what about the commented out code is somehow overwriting `msg.payload.woo2`

You set `msg.payload` to a string in that commented out code...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/4/d4191d3a522940fdf79f67cdec026402f73cafdf.png)

a string cannot have user properties

---

<div class="post-metadata">

**Author:** ![dclear](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dclear/32/9107_2.png) [@dclear](https://discourse.nodered.org/u/dclear)\
**Post date:** [6 March 2021 11:24 UTC](https://discourse.nodered.org/t/two-simple-bits-of-code-cant-coexist-together-im-clearly-doing-something-stupid/42143/3 "2021-03-06T11:24:53Z")

</div>

THANK YOU! 🙂 🙂  
I've spent ages on this. Much appreciated.

---

<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:** [20 March 2021 11:25 UTC](https://discourse.nodered.org/t/two-simple-bits-of-code-cant-coexist-together-im-clearly-doing-something-stupid/42143/4 "2021-03-20T11:25:15Z")

</div>

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