# Calculating with several if loops

**URL:** <https://discourse.nodered.org/t/calculating-with-several-if-loops/59490>\
**Category:** General\
**Created:** [7 March 2022 13:10 UTC](https://discourse.nodered.org/t/calculating-with-several-if-loops/59490 "2022-03-07T13:10:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [7 March 2022 13:10 UTC](https://discourse.nodered.org/t/calculating-with-several-if-loops/59490/1 "2022-03-07T13:10:09Z")

</div>

Hi

I have a dashboard with 3 options, when 1 is chosen there must be made a calculation.  
This choice is a string, but how can I say: if the string is equal with the other.  
Like in this case I choosed 3 x 230 in a normal case it must be the calculation on line 7.  
But the result is 'undefined'

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c50a6d7cfebeea17f28ef547354b2b202ac642b0.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/0/904342b6d1799f8d85ce2bc14044fbc788aaddf9.png)

---

<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:** [7 March 2022 15:34 UTC](https://discourse.nodered.org/t/calculating-with-several-if-loops/59490/2 "2022-03-07T15:34:25Z")

</div>

What is the first line supposed to be doing? Getting a value from global context?

for that, you use `global.get`

![chrome_SMvjOsYhTs](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/d/6d0383c578349f6f97cbee27c802391d48a65e33.gif)

PS This autocompletion feature ☝ is part of the monaco editor (you can get this in newer versions of node-red by setting the code editor setting in `settings.js`)

---

<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:** [22 March 2022 06:54 UTC](https://discourse.nodered.org/t/calculating-with-several-if-loops/59490/4 "2022-03-22T06:54:02Z")

</div>

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