Reputation: 1
I am new to Zapier and writing JavaSctipt. I tried to use a BMI script that I found with Zapier to start learning how to use the code in association with apps but when I test it in Zapier it returns this error:
We had trouble sending your test though. Please try again. Error:
Error: You did not define output
! Try output = {id: 1, hello: "world"};
// Calculate BMI
var calculateBmi = function calculateBmi() {
var weight = document.bmiForm.weight.value
var height = document.bmiForm.height.value
if (weight > 0 && height > 0) {
var finalBmi = weight / (height / 100 * height / 100)
document.bmiForm.bmi.value = finalBmi
if (finalBmi < 18.5) {
document.bmiForm.meaning.value = "Você está muito magro."
}
if (finalBmi > 18.5 && finalBmi < 25) {
document.bmiForm.meaning.value = "Você está saudável."
}
if (finalBmi > 25) {
document.bmiForm.meaning.value = "Você está com sobrepeso."
}
}
else {
alert("Por favor preencha os dados corretamente")
}
}
//-->
I'd really appreciate if someone can teach me what I need to do to export the results without errors or how I need to change my code to solve the this.
Upvotes: 0
Views: 512
Reputation: 5262
David here, from the Zapier Platform team.
Your issue is that you've defined a function, but never did anything with it!
If you look at the examples here, each either calls return
or sets the output
variable to something, both of which get results outside of the Zapier function.
Another note is that neither document
nor alert
are available in Node.js (those are for browsers). You'll want to use map in those values from an earlier step (however that input happens).
At the bottom of your code, you'll want to call calculateBmi(inputData.height, inputData.weight)
(once those values are correctly mapped in).
Let me know if you've got any other questions!
Upvotes: 1