# Logical operator with three variables

**URL:** <https://discourse.nodered.org/t/logical-operator-with-three-variables/45236>\
**Category:** General\
**Created:** [5 May 2021 21:18 UTC](https://discourse.nodered.org/t/logical-operator-with-three-variables/45236 "2021-05-05T21:18:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![steinerma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinerma/32/37666_2.png) [@steinerma](https://discourse.nodered.org/u/steinerma)\
**Post date:** [5 May 2021 21:18 UTC](https://discourse.nodered.org/t/logical-operator-with-three-variables/45236/1 "2021-05-05T21:18:56Z")

</div>

Hi, somehow I have an error that I can not find. I have three variables. Only when all three variables are "1", the output should be "1".  
The problem is that after deploy, every first time a variable is "1", the output becomes "1". If all variables are a "1" the node works correctly. Do you have a hint what I am doing wrong?

the function node:

```auto
var x = flow.get("dashboard");
var y = flow.get("start");
var z = flow.get("telegram");
if (x == 1 & y == 1 & z == 1) {
msg.payload = 1;
}
else {
msg.payload = 0;
}
return msg;

```

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [5 May 2021 21:24 UTC](https://discourse.nodered.org/t/logical-operator-with-three-variables/45236/2 "2021-05-05T21:24:17Z")

</div>

> [@steinerma](#):
>
> `if (x == 1 & y == 1 & z == 1) {`

This must be:

```auto
if (x == 1 && y == 1 && z == 1) {

```

> **[JavaScript Operators Reference](https://www.w3schools.com/jsref/jsref_operators.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

---

<div class="post-metadata">

**Author:** ![steinerma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinerma/32/37666_2.png) [@steinerma](https://discourse.nodered.org/u/steinerma)\
**Post date:** [7 May 2021 05:45 UTC](https://discourse.nodered.org/t/logical-operator-with-three-variables/45236/3 "2021-05-07T05:45:59Z")

</div>

Thanks a lot!

---

<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:** [21 May 2021 05:46 UTC](https://discourse.nodered.org/t/logical-operator-with-three-variables/45236/4 "2021-05-21T05:46:30Z")

</div>

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