# Simple if loop statement

**URL:** <https://discourse.nodered.org/t/simple-if-loop-statement/26056>\
**Category:** General\
**Created:** [4 May 2020 11:22 UTC](https://discourse.nodered.org/t/simple-if-loop-statement/26056 "2020-05-04T11:22:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MARAUDER2003](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@MARAUDER2003](https://discourse.nodered.org/u/MARAUDER2003)\
**Post date:** [4 May 2020 11:22 UTC](https://discourse.nodered.org/t/simple-if-loop-statement/26056/1 "2020-05-04T11:22:44Z")

</div>

Hello,  
I'm very new to Node-Red, and I'm also very knew to programming. I'm currently using the function node to write the following:

if (msg.payload.pi/11 === 0){  
msg.payload = 1;  
} else {  
msg.payload = 2;  
}  
return msg;

It appears the problem lies with the /11 part and it should be something like

if (msg.payload.match ( ) === 0){  
msg.payload = 1;  
} else {  
msg.payload = 2;  
}  
return msg;

My problem is that I don't know what to write inside the ( ) of the match part. Does it have to be some sort of JSON expression?  
I'm getting this output (msg.payload.pi/11) from a rpi gpio in node that outputs a digital signal out of pin 11 from a raspberry pi.  
Thanks for your help.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [4 May 2020 11:52 UTC](https://discourse.nodered.org/t/simple-if-loop-statement/26056/2 "2020-05-04T11:52:19Z")

</div>

If you look at the info tab of the `rpi-gpio in` node you will see the following

### [Outputs](http://localhost:1880/#)

`payload` number  
the payload will be a 1 or a 0.

`topic` string  
the topic will be set to  
`pi/{the pin number}` .

so you want to test `msg.payload`. If you want to check what pin returned the message, then you would be looking at msg.topic.

You should take a few minutes to read thru the section in the documentation [https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)  
which should help you understand how to work with the contents of messages.

And welcone to the forum 🎆

---

<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:** [3 July 2020 11:54 UTC](https://discourse.nodered.org/t/simple-if-loop-statement/26056/3 "2020-07-03T11:54:24Z")

</div>

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