# Math.pow for power of a number

**URL:** <https://discourse.nodered.org/t/math-pow-for-power-of-a-number/63067>\
**Category:** General\
**Created:** [25 May 2022 19:20 UTC](https://discourse.nodered.org/t/math-pow-for-power-of-a-number/63067 "2022-05-25T19:20:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![btbr](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@btbr](https://discourse.nodered.org/u/btbr)\
**Post date:** [25 May 2022 19:20 UTC](https://discourse.nodered.org/t/math-pow-for-power-of-a-number/63067/1 "2022-05-25T19:20:36Z")

</div>

Hello All,

I am trying to do this equation in a function Node -

 ![Screen Shot 2022-05-25 at 20.16.21](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/76e0c0fc44a1950def1923950d0fded5499c460c.png)

RAW = sensor value = w. I am writing it like this -

var VWC = 6.771 \* math.pow(10, -10) \* math.pow(w, -3)-5.105 \* math.pow(10, -6) \* math.pow(w, 2) + 1.302 \* math.pow(10, -2) \* w -10.848;

and it is returning this error -

ReferenceError: math is not defined (line 3, col 19)

This is the full script in the function node -

var w = msg.payload.col14;

var VWC = 6.771 \* math.pow(10, -10) \* math.pow(w, -3)-5.105 \* math.pow(10, -6) \* math.pow(w, 2) + 1.302 \* math.pow(10, -2) \* w -10.848;

msg.payload=VWC  
return msg;

Does anyone possibly know if I'm close or a million miles away?

If anyone knows how to fix it would be fantastic.

---

<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:** [25 May 2022 19:23 UTC](https://discourse.nodered.org/t/math-pow-for-power-of-a-number/63067/2 "2022-05-25T19:23:53Z")

</div>

JavaScript is case sensitive.

[Math.pow()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)

---

<div class="post-metadata">

**Author:** ![btbr](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@btbr](https://discourse.nodered.org/u/btbr)\
**Post date:** [25 May 2022 19:28 UTC](https://discourse.nodered.org/t/math-pow-for-power-of-a-number/63067/3 "2022-05-25T19:28:57Z")

</div>

Thank you very much!!!!

Worked straight away.

---

<div class="post-metadata">

**Author:** ![crxporter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crxporter/32/25734_2.png) [@crxporter](https://discourse.nodered.org/u/crxporter)\
**Post date:** [26 May 2022 12:33 UTC](https://discourse.nodered.org/t/math-pow-for-power-of-a-number/63067/4 "2022-05-26T12:33:15Z")

</div>

Alternate option is using the exponentiation operator. That's `**` ... I was doing exponents just last week and first tried with Math.pow (which works fine) but found it simpler to just use the double asterisk. Could be easier to read your long equation with this...

So 4^8 would just be `4 ** 8` Instead of `Math.pow(4, 8)`

---

<div class="post-metadata">

**Author:** ![btbr](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@btbr](https://discourse.nodered.org/u/btbr)\
**Post date:** [26 May 2022 21:45 UTC](https://discourse.nodered.org/t/math-pow-for-power-of-a-number/63067/5 "2022-05-26T21:45:58Z")

</div>

Nice. Thanks!

---

<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:** [9 June 2022 21:46 UTC](https://discourse.nodered.org/t/math-pow-for-power-of-a-number/63067/6 "2022-06-09T21:46:29Z")

</div>

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