0
Api returns no data found please help
https://sololearn.com/compiler-playground/Wc673BJ31yJq/?ref=app When I run this on one compiler it returns this: (Search example chicken) Chicken: carbohydrates undefined G Could somebody please help? I have parsed the API more thoroughly and have tried several code options bit I am struggling to see the wood for the trees at this stage.
5 Réponses
+ 1
hola
https://www.sololearn.com/ru/compiler-playground/WdFueWyf948A
1. u need to first declare and initialize the apiKey and searchTerm variables, and then use them in the URL
2. ur API returns 'value', not 'amount'
the code attempts to access amount and unitName from the nutrient objects, but the API returns value instead of amount
currently, when processing the data, we get the following result:
Results for Pancake
Total Carbohydrates: 41.4 G - A type of complex carbohydrate found in many foods.
Sugar: 12.9 G - A simple carbohydrate often found in sweet foods and drinks.
0
https://www.sololearn.com/ru/compiler-playground/WNsYlkbOMx3K
// Сhanges:
const url = `https://api.nal.usda.gov/fdc/v1/foods/search?api_key=${apiKey}&query=${encodeURIComponent(searchTerm)}&dataType=Branded`;
const totalCarbohydrates = food.foodNutrients.find(nutrient => nutrient.nutrientNumber === '205');
const sugar = food.foodNutrients.find(nutrient => nutrient.nutrientNumber === '269');
0
Thank you so much aqukai. Will try this later today.
0
https://sololearn.com/compiler-playground/WBkH03WHp4P2/?ref=app
Hey aqukai, I am new to coding so please forgive me.....
Is this correct? If so it is still not returning anything and I cannot see what I am doing wrong.
Thank you for your time
0
Hola,
Many thanks aqukai, I actually managed to sort the code in the end. Albeit that it took me a long time.lol.
I really appreciate you coming back to me again though. It really helps to here views from experienced developers.