I’m just starting with Zapier and JavaScript development. I’m trying to learn by working with a health calculator script, but I keep getting an error when testing it in Zapier.
The error message says: We had trouble sending your test though. Please try again. Error: You did not define output! Try output = {id: 1, hello: "world"};
Here’s my code:
// Health Score Calculator
var computeHealthScore = function computeHealthScore() {
var bodyWeight = inputForm.weight.value
var bodyHeight = inputForm.height.value
if (bodyWeight > 0 && bodyHeight > 0) {
var healthIndex = bodyWeight / (bodyHeight / 100 * bodyHeight / 100)
inputForm.result.value = healthIndex
if (healthIndex < 18.5) {
inputForm.status.value = "Underweight category"
}
if (healthIndex > 18.5 && healthIndex < 25) {
inputForm.status.value = "Normal weight range"
}
if (healthIndex > 25) {
inputForm.status.value = "Overweight category"
}
}
else {
alert("Please enter valid values")
}
}
Can someone help me understand what I need to modify to make this work properly in Zapier? I need to know how to structure the output correctly so it doesn’t throw errors.
Your code’s built for web forms, not Zapier’s JavaScript runtime. In Zapier, you need an output variable with the data you want to pass along. Right now you’re referencing inputForm, which doesn’t exist in Zapier. To fix this, grab your weight and height from the input bundle, perform your BMI calculation, and then set output = {bmi: healthIndex, status: "your calculated status"}. The key point is that Zapier requires you to explicitly define what data is passed to the next step through that output variable.
zapier requires an output variable at the end. your code’s accessing browser form elements which don’t exist in zapier’s enviroment. use var weight = inputData.weight; var height = inputData.height; to get your data, calculate bmi and finish with output = {result: healthIndex, category: statusValue};.
Your script won’t work because it’s written for browsers, not Zapier. You’re trying to access DOM elements like inputForm, but Zapier’s Code action doesn’t have a DOM. You need to get your data from inputData.weight and inputData.height instead - that’s how Zapier passes data from previous steps. Calculate your BMI, then return it like output = {bmi: healthIndex, category: statusMessage}. Ditch the alert and form stuff - none of that works in Zapier’s serverless setup.