Zapier Code: Trouble with conditional statements returning specific values

Hey everyone! I’m stuck on a Zapier code issue. I’m trying to set up a simple condition that gives a number from 1 to 10 based on another number. For instance, if the input is 7200000, it should give me 2. Here’s what I’ve got so far:

let result;
if (input.value == 7200000) {
  result = 2;
} else {
  result = input.value;
}

But I’m getting an error saying I need to return a single object or array of objects. I’m not sure how to fix this. Any ideas on how to make this work in Zapier? I’d really appreciate some help! Thanks a bunch!

hey liam, i’ve run into this before. zapier can be picky bout output. try returning an object like this:

return {result: input.value === 7200000 ? 2 : input.value};

this uses a ternary operator to make it more compact. hope it helps!

I’ve dealt with similar Zapier code challenges before. One thing to consider is that Zapier often expects numbers to be strings. Here’s an approach that might work better:

let value = input.value.toString();
let result = value;

if (value === '7200000') {
  result = '2';
} else if (value === '14400000') {
  result = '4';
} else if (value === '21600000') {
  result = '6';
}

return { output: result };

This handles multiple conditions and converts everything to strings. It’s more flexible and should play nice with Zapier’s expectations. Remember to adjust the conditions based on your specific needs. Also, consider using a mapping object if you have many conditions to check.

I’ve encountered a similar issue with Zapier’s code steps. The problem is that Zapier expects a specific output format. Try wrapping your result in an object like this:

let result;
if (input.value === 7200000) {
  result = 2;
} else {
  result = input.value;
}
return {output: result};

This should satisfy Zapier’s requirement for returning an object. Also, consider using strict equality (===) for more precise comparisons. If you need to handle multiple conditions, you might want to look into using a switch statement or even an object lookup for better readability and performance.