# Function node: How to "OR" operate

**URL:** <https://discourse.nodered.org/t/function-node-how-to-or-operate/48245>\
**Category:** General\
**Created:** [10 July 2021 12:14 UTC](https://discourse.nodered.org/t/function-node-how-to-or-operate/48245 "2021-07-10T12:14:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RonMa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ronma/32/42531_2.png) [@RonMa](https://discourse.nodered.org/u/RonMa)\
**Post date:** [10 July 2021 12:14 UTC](https://discourse.nodered.org/t/function-node-how-to-or-operate/48245/1 "2021-07-10T12:14:49Z")

</div>

Hi guys,  
For one of my Alexa based flows, I´m trying to define the room in which the echo device is located that one is speaking to. Unfortunately, the corresponding "Alexa Event" node does not deliver the information about the group which the device is assigned to. So this again means DIY 😄

In order to do so I´m trying to create a function node, that sets a flow variable for the certain room based on the device the event was initiated from. And that´s how it looks like:

```auto
if ((msg.payload.data.domain === "Routines"))
{
flow.set("ActiveEcho",msg.payload.deviceSerialNumber)
}

if ((msg.payload.name === "Büro Echo"||"Büro Echo Show")){
    flow.set("ActiveRoom","Büro")
    
}else if (msg.payload.name === "Bad Echo") {
    flow.set("ActiveRoom","Badezimmer")
    
}else if (msg.payload.name === "Kinderzimmer Echo"){
    flow.set("ActiveRoom","Kinderzimmer")
    
}else if ((msg.payload.name === "Küche Echo"||"Küche Echo Show")){
    flow.set("ActiveRoom","Küche")
    
}else if ((msg.payload.name === "Schlafzimmer Echo links"||"Schlafzimmer Echo rechts")){
    flow.set("ActiveRoom","Schlafzimmer")

}else if ((msg.payload.name === "Couch links"||"Couch rechts"||"Wohnzimmer Echo Show"||"Wohnzimmer Echo Studio")){
    flow.set("ActiveRoom","Wohnzimmer")
    
}else{
    flow.set("ActiveRoom","undefined")
}

```

So far, so good. However, no matter which room I initiate the alexa routine from, the "ActiveRoom" variable is always set to "Büro". Interesting wise, the "ActiveEcho" flow variable is set correctly. Now what am I doing wrong here?

---

<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:** [10 July 2021 12:33 UTC](https://discourse.nodered.org/t/function-node-how-to-or-operate/48245/2 "2021-07-10T12:33:23Z")

</div>

> [@RonMa](#):
>
> the "ActiveRoom" variable is always set to "Büro".

> [@RonMa](#):
>
> `if ((msg.payload.name === "Büro Echo"||"Büro Echo Show")){`

If I write this line in plain english, it says...

`If msg.payload.name equals "Büro Echo" OR "Büro Echo Show" is something`

To explain a little further, If the LEFT HAND side of an `||` is false, the RIGHT HAND SIDE is evaluated. "Büro Echo Show" evaluates to `true` in a boolean test.

change it to...

```auto
if (msg.payload.name === "Büro Echo" || msg.payload.name === "Büro Echo Show") {
   //...
}

```

(And all the other places you have used `||`)

---

<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:** [10 July 2021 12:40 UTC](https://discourse.nodered.org/t/function-node-how-to-or-operate/48245/3 "2021-07-10T12:40:49Z")

</div>

You might be better off with a [`switch`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch) statement TBH..

```javascript
if ((msg.payload.data.domain === "Routines")) {
    flow.set("ActiveEcho",msg.payload.deviceSerialNumber)
}

switch (msg.payload.name) {
    case "Büro Echo":
    case "Büro Echo Show":
        flow.set("ActiveRoom", "Büro")
        break;
    case "Bad Echo":
        flow.set("ActiveRoom", "Badezimmer")
        break;
    case "Kinderzimmer Echo":
        flow.set("ActiveRoom", "Kinderzimmer")
        break;
    case "Küche Echo":
    case "Küche Echo Show":
        flow.set("ActiveRoom", "Küche")
        break;
    case "Schlafzimmer Echo links":
    case "Schlafzimmer Echo rechts":
        flow.set("ActiveRoom", "Schlafzimmer")
        break;
    case "Couch links":
    case "Couch rechts":
    case "Wohnzimmer Echo Show":
    case "Wohnzimmer Echo Studio":
        flow.set("ActiveRoom", "Wohnzimmer")
        break;
    default:
        flow.set("ActiveRoom", "undefined")
}

```

---

<div class="post-metadata">

**Author:** ![RonMa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ronma/32/42531_2.png) [@RonMa](https://discourse.nodered.org/u/RonMa)\
**Post date:** [10 July 2021 12:50 UTC](https://discourse.nodered.org/t/function-node-how-to-or-operate/48245/4 "2021-07-10T12:50:09Z")

</div>

Works like a charm - Thanks much @Steve-Mcl ! 👍

---

<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:** [24 July 2021 17:59 UTC](https://discourse.nodered.org/t/function-node-how-to-or-operate/48245/6 "2021-07-24T17:59:57Z")

</div>

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