# && and || can not be combined?

**URL:** https://discourse.nodered.org/t/and-can-not-be-combined/46425
**Category:** General
**Created:** [28 May 2021 21:04 UTC](https://discourse.nodered.org/t/and-can-not-be-combined/46425 "2021-05-28T21:04:38Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![edstobi](https://avatars.discourse-cdn.com/v4/letter/e/aca169/32.png) [@edstobi](https://discourse.nodered.org/u/edstobi)
#### Post date: [28 May 2021 21:04 UTC](https://discourse.nodered.org/t/and-can-not-be-combined/46425/1 "2021-05-28T21:04:38Z")

</div>

HI and sorry  
I need again help to figure out a maybe syntax problem

if( a=="1" || b=="10" || c=="100"){ ......... working, 😀  
if( (a=="1" || b=="10" || c=="100") && d \>1000){ ........is not working.

do I have a bracket problem? 🤔  
THX

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [28 May 2021 21:23 UTC](https://discourse.nodered.org/t/and-can-not-be-combined/46425/2 "2021-05-28T21:23:44Z")

</div>

does changing it to (d\>1000) do anything?

---

<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: [28 May 2021 21:24 UTC](https://discourse.nodered.org/t/and-can-not-be-combined/46425/3 "2021-05-28T21:24:25Z")

</div>

Is a,b,c and d a string or an number?

With **a=="1"** you a comparing a string, not a number.  
**d \>1000** can only works with a number.

Maybe you can show where the values are coming from and what type variable they are.

`if( (a==1 || b==10 || c==100) && d > 1000){`  
this works if all your variable are number

---

<div class="post-metadata">

### Author: ![edstobi](https://avatars.discourse-cdn.com/v4/letter/e/aca169/32.png) [@edstobi](https://discourse.nodered.org/u/edstobi)
#### Post date: [28 May 2021 22:11 UTC](https://discourse.nodered.org/t/and-can-not-be-combined/46425/4 "2021-05-28T22:11:37Z")

</div>

@ edje11  
a, b c are strings coming von mqtt,  
d is a counter so it is a number  
@cymplecy  
no no change, not working

---

<div class="post-metadata">

### Author: ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)
#### Post date: [29 May 2021 04:42 UTC](https://discourse.nodered.org/t/and-can-not-be-combined/46425/5 "2021-05-29T04:42:18Z")

</div>

This code works fine:

```auto
let a="2";
let b="3";
let c="100";
let d=1001;

if( (a=="1" || b=="10" || c=="100") && d >1000){
    msg.payload = "OK";
    return msg;    
}

```

If you then change to this, you won't see ok in the debug so this code is working

```auto
let a="2";
let b="3";
let c="100";
let d=1000;

if( (a=="1" || b=="10" || c=="100") && d >1000){
    msg.payload = "OK";
    return msg;    
}

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/1/f144528f33cdf4af2141ce0006e87bb464d0ea7b.png)

---

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [29 May 2021 05:37 UTC](https://discourse.nodered.org/t/and-can-not-be-combined/46425/6 "2021-05-29T05:37:00Z")

</div>

> [@edstobi](#):
>
> a, b c are strings coming von mqtt,  
> d is a counter so it is a number

To be sure, stick this into your function.

```auto
node.warn("a is "+typeof a +", b is "+typeof b +", c is "+typeof c +", d is "+typeof d)

```

---

<div class="post-metadata">

### Author: ![edstobi](https://avatars.discourse-cdn.com/v4/letter/e/aca169/32.png) [@edstobi](https://discourse.nodered.org/u/edstobi)
#### Post date: [29 May 2021 13:55 UTC](https://discourse.nodered.org/t/and-can-not-be-combined/46425/7 "2021-05-29T13:55:28Z")

</div>

Thanks for the tip with node.warn. My if syntax is correct only a value is a number instead of a string. So I have two strings and two numbers. With this knowledge my function is running and learned something new again!  
THX

---

<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: [12 June 2021 13:56 UTC](https://discourse.nodered.org/t/and-can-not-be-combined/46425/8 "2021-06-12T13:56:04Z")

</div>

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