function reformatFood(foodFromApi) {
  let convertedFood = {
    brand: "",
    name: "",
    calories: 0,
    carbs: 0,
    fat: 0,
    protein: 0,
  };

  convertedFood.name = foodFromApi.description;
  convertedFood.brand = foodFromApi.brandOwner;

  // Loop through the food nutrients and find carbs, fat, and protein
  for (let i = 0; i < foodFromApi.foodNutrients.length; i++) {
    if (foodFromApi.foodNutrients[i].nutrientId == 1008) {
      convertedFood.calories = foodFromApi.foodNutrients[i].value;
    } else if (foodFromApi.foodNutrients[i].nutrientId == 1005) {
      convertedFood.carbs = foodFromApi.foodNutrients[i].value;
    } else if (foodFromApi.foodNutrients[i].nutrientId == 1004) {
      convertedFood.fat = foodFromApi.foodNutrients[i].value;
    } else if (foodFromApi.foodNutrients[i].nutrientId == 1003) {
      convertedFood.protein = foodFromApi.foodNutrients[i].value;
    }
  }

  return convertedFood;
}
// Convert food returned in api to a food object that can be inserted into firebase database
Convert food returned in api to a food object that can be inserted into firebase database
Convert food returned in api to a food object that can be inserted into firebase database
function reformatFood(foodFromApi) {
  let convertedFood = {
    brand: "",
    name: "",
    calories: 0,
    carbs: 0,
    fat: 0,
    protein: 0,
  };
  convertedFood.name = foodFromApi.description;
  convertedFood.brand = foodFromApi.brandOwner;
  for (let i = 0; i < foodFromApi.foodNutrients.length; i++) {
    if (foodFromApi.foodNutrients[i].nutrientId == 1008) {
      convertedFood.calories = foodFromApi.foodNutrients[i].value;
    } else if (foodFromApi.foodNutrients[i].nutrientId == 1005) {
      convertedFood.carbs = foodFromApi.foodNutrients[i].value;
    } else if (foodFromApi.foodNutrients[i].nutrientId == 1004) {
      convertedFood.fat = foodFromApi.foodNutrients[i].value;
    } else if (foodFromApi.foodNutrients[i].nutrientId == 1003) {
      convertedFood.protein = foodFromApi.foodNutrients[i].value;
    }
  }
  return convertedFood;
}
function reformatFood ( foodFromApi ) { let convertedFood = { brand : "" , name : "" , calories : 0 , carbs : 0 , fat : 0 , protein : 0 , } ; convertedFood . name = foodFromApi . description ; convertedFood . brand = foodFromApi . brandOwner ; for ( let i = 0 ; i < foodFromApi . foodNutrients . length ; i ++ ) { if ( foodFromApi . foodNutrients [ i ] . nutrientId == 1008 ) { convertedFood . calories = foodFromApi . foodNutrients [ i ] . value ; } else if ( foodFromApi . foodNutrients [ i ] . nutrientId == 1005 ) { convertedFood . carbs = foodFromApi . foodNutrients [ i ] . value ; } else if ( foodFromApi . foodNutrients [ i ] . nutrientId == 1004 ) { convertedFood . fat = foodFromApi . foodNutrients [ i ] . value ; } else if ( foodFromApi . foodNutrients [ i ] . nutrientId == 1003 ) { convertedFood . protein = foodFromApi . foodNutrients [ i ] . value ; } } return convertedFood ; }
Convert food returned in api to a food object that can be inserted into firebase database
Convert food returned in api to a food object that can be inserted into firebase database
// Loop through the food nutrients and find carbs, fat, and protein