Hello,

So my problem is that I’m trying to get a result from the text area based on the dropdown options through a function that I created, but have no clue as to what to do about it. Basically, the purpose of this function is for the user to select a type of food and beverage, and what exactly does the user eat and drink, and the drop down menus are based on data from a website. For the most part, I was able to filter into separate lists and function them for the user to select the options, but when it comes to publishing the result, the result doesn’t work. To prove my point, here’s the function that I’m working on:

```
function CalculatingResult (meal) {
var result;
var decision;
var filteredFoodTypes;
var filteredBeverageTypes;
for (var x = 0; x < filteredFoodTypesList.length; x++) {
filteredFoodTypes = filteredFoodTypesList[x];
if (selectedCategoryOfFood == filteredFoodTypes) {
foodCalories = foodCalories[x];
}
}
for (var y = 0; y < filteredBeverageTypesList.length; y++) {
filteredBeverageTypes = filteredBeverageTypesList[y];
if (selectedCategoryOfBeverage == filteredBeverageTypes) {
beverageCalories = beverageCalories[y];
}
totalCalories = foodCalories + beverageCalories;
if (meal == "Lunch" || meal == "Dinner" && totalCalories >= 500 && totalCalories <= 700) {
decision = "Hello, " + name + ", but this would be an acceptable " + meal.toLowerCase() + ", because " + selectedCategoryOfFood.toLowerCase() + " contains " + foodCalories + " calories, while " + selectedCategoryOfBeverage + " contains " + beverageCalories + " calories, which results in the total of " + totalCalories + " calories , which is therefore acceptable. ";
} else {
decision = "Hello, " + name + ", but this would be an unacceptable " + meal.toLowerCase() + ", because " + selectedCategoryOfFood.toLowerCase() + " contains " + foodCalories + " calories, while " + selectedCategoryOfBeverage + " contains " + beverageCalories + " calories, which results in the total of " + totalCalories + " calories , which is therefore unacceptable. ";
}
for (var c = 1; c < 4; c++) {
result = setProperty("RecommendationTextArea"+c, "text", decision);
}
return result;
}
}
```

In order to figure out where some of these things are coming from. I provided some examples of some onEvents that I wrote in the program. These are the following

```
onEvent("CategoryBeverageDropdown3", "change", function ( ) {
selectedCategoryOfBeverage = getText("CategoryBeverageDropdown3");
});
onEvent("CategoryFoodDropdown3", "change", function ( ) {
selectedCategoryOfFood = getText("CategoryFoodDropdown3");
});
var foodCalories = getColumn("Fast Food Nutrition", "Calories");
var beverageCalories = getColumn("Beverages Nutrition", "Calories");
var totalCalories;
```

Based on this information, the result that I was expecting was that…

Hi, (your name), but this would be an unacceptable dinner, because Sushi Topped With Tuna contains 100 calories, while Chocolate Almond Milk contains 50 calories, which results in the total of 150 calories, which is therefore unacceptable.

Instead, it shows me as…

Hi, (your name), but this would be an unacceptable dinner, because Sushi Topped With Tuna contains 284 calories, which Chocolate Almond Milk contains 15 calories, which results in the total of 299 calories, which is therefore unacceptable.

This isn’t right because I want Sushi Topped With Tuna to have 100 calories and the Chocolate Almond Milk to have 50 calories, and it seems like the values are pretty much the length of the lists which is something that I don’t want, and I have no clue as to how to fix this problem, despite the many attempts that I tried to do.

Thanks.