#  I don't understand where is the mistake

**URL:** <https://discourse.nodered.org/t/i-dont-understand-where-is-the-mistake/62642>\
**Category:** General\
**Created:** [15 May 2022 10:42 UTC](https://discourse.nodered.org/t/i-dont-understand-where-is-the-mistake/62642 "2022-05-15T10:42:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JJ22](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@JJ22](https://discourse.nodered.org/u/JJ22)\
**Post date:** [15 May 2022 10:42 UTC](https://discourse.nodered.org/t/i-dont-understand-where-is-the-mistake/62642/1 "2022-05-15T10:42:39Z")

</div>

Hello!  
I am still new to javascript. I need to create a code for the equipment selection configurator (calculator) so that instead of a number (answer) it gives a link to the site.  
Started simple, here is my code:

```auto
U=msg.payload.U;
I=msg.payload.I;
cosf=msg.payload.cosf;
kpd=msg.payload.kpd;

msg.payload.result = Math.round((Math.sqrt(3)*U*I*cosf*kpd)/1000);

if ('0.18'<=msg.payload.result and msg.payload.result<='2.2')
{
msg.payload.result='https://owen.ru1';
}
else 
{
    msg.payload.result='not';
}
else if ('0.37'<=msg.payload.result and msg.payload.result<='4')
{
   msg.payload.result='https://owen.ru2'; 
}
else if ('5.5'<=msg.payload.result and msg.payload.result<='22')
{
   msg.payload.result='https://owen.ru3'; 
}
return msg;

```

I got one porridge(

---

<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:** [15 May 2022 10:45 UTC](https://discourse.nodered.org/t/i-dont-understand-where-is-the-mistake/62642/2 "2022-05-15T10:45:46Z")

</div>

You would be better switching to `monaco` editor (search the forum for how to) as it is far better at highlighting your issues in JavaScript

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

Here is your code fixed up...

```javascript
const U = msg.payload.U;
const I = msg.payload.I;
const cosf = msg.payload.cosf;
const kpd = msg.payload.kpd;

msg.payload.result = Math.round((Math.sqrt(3) * U * I * cosf * kpd) / 1000);

if (0.18 <= msg.payload.result && msg.payload.result <= 2.2) {
    msg.payload.result = 'https://owen.ru1';
} else if (0.37 <= msg.payload.result && msg.payload.result <= 4) {
    msg.payload.result = 'https://owen.ru2';
} else if (5.5 <= msg.payload.result && msg.payload.result <= 22) {
    msg.payload.result = 'https://owen.ru3';
} else {
    msg.payload.result = 'not';
}
return msg;

```

---

<div class="post-metadata">

**Author:** ![JJ22](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@JJ22](https://discourse.nodered.org/u/JJ22)\
**Post date:** [15 May 2022 11:06 UTC](https://discourse.nodered.org/t/i-dont-understand-where-is-the-mistake/62642/3 "2022-05-15T11:06:41Z")

</div>

Thank you very much, you helped out!

---

<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:** [14 July 2022 11:07 UTC](https://discourse.nodered.org/t/i-dont-understand-where-is-the-mistake/62642/4 "2022-07-14T11:07:22Z")

</div>

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