Reputation: 1
Essentially what I'm attempting to do is circumvent when users enter a number in a non-standard format. For example:
1.5 million should be 1500000
Previous Zap step extracts the number using the Formatter > Extract Number function. So the result is the variable rawNum and the original number is noformatNum.
var str = inputData.noformatNum;
var n = inputData.noformatNum.includes ("million");
if (n = true) return {
finalNum: Number(inputData.rawNum) * 1000000
};
else return { finalNum : inputData.noformatNum };
It works in that it completes the operation and turns 1.5 to 1500000, but it executes each time, even if noformatNum doesn't include "million" in the string. I'm not super experienced with Javascript, but after digging around W3C and the Zapier documentation for a couple hours I'm stumped. Any help is much appreciated. Thanks!
Upvotes: 0
Views: 235
Reputation: 543
It looks like there's a small but significant syntax issue here. You'll want to use a triple equal sign ===
instead of a single =
in your conditional.
if (n = true) return {
should be
if (n === true) return {
In an if...else
statement, the part in parenthesis (the "condition") should be something that evaluates to either a "truthy" or "falsy" value. (MDN)
n = true
assigns the value of true
to the variable n
, so JavaScript considers the whole thing "truthy" no matter what.
n === true
compares n
to true
, which is what you want for the if...else
statement to work. The value will be "truthy" or "falsy" depending on the value of n
.
Upvotes: 1