//this is from Ron https://renickbell.net/middleschool/doku.php?id=students:ron-calories-fried-rice
function sumArray (inputArray) {
let sum = 0;
for (let i = 0; i < inputArray.length; i++) {
sum = sum + inputArray[i]
}
return sum}
///this function is form https://renickbell.net/middleschool/doku.php?id=students:yuna-fried-rice-protein-calculation-in-code
///class is talliing the function what will the Ingredinet have
class Ingredient {
constructor (name, proteinAmount100g, amountInDish,inputArray,allAmount,ingredients,allProtein,allCarb,allFat,allFiber,allIron,allSodium,allCalcium,allVitaminD)
{ this.name = name;
this.proteinAmount100g = proteinAmount100g;
this.amountInDish = amountInDish;
this.calculatedProtein = undefined;
this.inputArray=inputArray;
this.allAmount=allAmount;
this.ingredients=ingredients;
this.allProtein=allProtein;
this.allCarb=allCarb;
this.allFat=allFat;
this.allFiber=allFiber;
this.allIron=allIron;
this.allSodium=allSodium;
this.allCalcium=allCalcium;
this.allVitaminD=allVitaminD;
}
}
///how heavy it is
function calculateProtein (ingredientObject) {
ingredientObject.calculatedProtein = ingredientObject.proteinAmount100g / 100 * ingredientObject.amountInDish
return ingredientObject
}
/// It is helping us to Calculate
// this is from Ron https://renickbell.net/middleschool/doku.php?id=students:ron-fried-rice-new
let allIngredient = [
new Ingredient ('carrot',25, 0.9, 9.6, 0.2,2.8, 69, 33, 0.3, 0 ),
new Ingredient ('rice', 450, 4, 28,2.6,0.7, 1, 10, 1.2, 0 ),
new Ingredient ('peas', 10, 5.4, 15, 0.4, 5.7, 5, 25, 1.5, 0 ),
new Ingredient ('ham',25, 21, 0.4, 15, 0, 941, 8, 1.4, 0),
]
allIngredient = allIngredient.map(calculateProtein)
//this is from ron https://renickbell.net/middleschool/doku.php?id=students:ron-calories-fried-rice
function friedriceNutrition (IngredientObject){
//Protein
IngredientObject.calculatedProtein = IngredientObject.ProteinAmount100g / 100 * IngredientObject.amountInDish
return IngredientObject
//Carbs
IngredientObject.calculatedCarbs = IngredientObject.CarbsAmount100g / 100 * IngredientObject.amountInDish
return IngredientObject
//Fat
IngredientObject.calculatedFat = IngredientObject.FatAmount100g / 100 * IngredientObject.amountInDish
return IngredientObject
//Fiber
IngredientObject.calculatedFiber = IngredientObject.FiberAmount100g / 100 * IngredientObject.amountInDish
return IngredientObject
//Sodium
IngredientObject.calculatedSodium = IngredientObject.SodiumAmount100mg / 100 * IngredientObject.amountInDish
return IngredientObject
//Calcium
IngredientObject.calculatedCalcium = IngredientObject.CalciumAmount100mg / 100 * IngredientObject.amountInDish
return IngredientObject
//Iron
IngredientObject.calculatedIron = IngredientObject.IronAmount100mg / 100 * IngredientObject.amountInDish
return IngredientObject
//VitaminD
IngredientObject.calculatedVitaminD = IngredientObject.VitaminDAmount100mg / 100 * IngredientObject.amountInDish
return IngredientObject
//Calories
IngredientObject.calculatedCalories = IngredientObject.CaloriesAmount100g / 100 * IngredientObject.amountInDish;
return IngredientObject
}
//new array
//this is form https://renickbell.net/middleschool/doku.php?id=students:ron-cal-fried-rice
function nutritionPrinter (inputArray, allAmount, ingredients, allProtein, allCarb, allFat, allFiber, allIron, allSodium, allCalcium, allVitaminD) {
inputArray.forEach(i => {
console.log("the ingredient name is",i.name);
console.log("the ingredientamount is ",i.ingredientAmount);
console.log("the amount of protein100g",i.protein100g);
console.log("the amount of carbs100g", i.carbs100g);
console.log("the amount of fat100g",i.fat100g);
console.log("the amount of fiber100g",i.fiber100g);
console.log("the amount of iron100g",i.iron100g);
console.log("the amount of sodium100g",i.sodium100g);
console.log("the amount of calcium100g",i.calcium100g);
console.log("the amount of vitaminD100g",i.vitaminD100g)
console.log("the amount of Calories100g",i.Calories100g)
})
}
//print outhuman readable
//https://renickbell.net/middleschool/doku.php?id=students:ron-calories-fried-rice
//this can help me to do Print the nutrition
function totalNutrition (ingredientArray) {
ingredientArray = ingredientArray.map(friedriceNutrition)
let allProteinValues = ingredientArray.map(o => o.calculatedProtein)
let allCarbValues = ingredientArray.map(o => o.calculatedCarbs)
let allFatValues = ingredientArray.map(o => o.calculatedFat)
let allFiberValues = ingredientArray.map(o => o.calculatedFiber)
let allIronValues = ingredientArray.map(o => o.calculatedIron)
let allSodiumValues = ingredientArray.map(o => o.calculatedSodium)
let allCalciumValues = ingredientArray.map(o => o.calculatedCalcium)
let allVitaminDValues = ingredientArray.map(o => o.calculatedVitaminD)
let allCaloriesValues = ingredientArray.map(o => o.calculatedCalories)
let totalProtein = sumArray (allProteinValues)
let totalCarb = sumArray (allCarbValues)
let totalFat = sumArray (allFatValues)
let totalFiber = sumArray (allFiberValues)
let totalIron = sumArray (allIronValues)
let totalSodium = sumArray (allSodiumValues)
let totalCalcium = sumArray (allCalciumValues)
let totalVitaminD = sumArray (allVitaminDValues)
let totalCalories = sumArray (allCaloriesValues)
nutritionPrinter (ingredientArray, allProtein,allCarb, allFat,allFiber, allIron, allSodium, allCalcium, allVitaminD,allCalories)
let nutritionObj =
{
name:'fried rice',
protein: allProtein,
carb: allCarb,
fat: allFat,
fiber: allFiber,
iron: allIron,
sodium: allSodium,
calcium: allCalcium,
vitaminD: allVitaminD,
calories: allCalories,
}
console.log('the name of this dish is ', nutrition.name);
console.log('the total amount of protein is ', nutrition.protein);
console.log('the total amount of carb is ', nutrition.carb);
console.log('the total amount of fat is ', nutrition.fat);
console.log('the total amount of fiber is ', nutrition.fiber);
console.log('the total amount of iron is ', nutrition.iron);
console.log('the total amount of sodium is ', nutrition.sodium);
console.log('the total amount of calcium is ', nutrition.calcium);
console.log('the total amount of vitaminD is ', nutrition.vitaminD);
console.log('the total amount of calories is ', nutrition.calories);
return nutritionObj
}
//this is from https://renickbell.net/middleschool/doku.php?id=core:nutrition100gfunction it is school
smoothie1 = totalNutrition(allIngredient)
smoothie1.ingredients[0]
function calculateServing (nutritionObj) {
let ratio = 100/nutritionObj.weight;
for (nutrition in nutritionObj) {
if (!isNaN(nutritionObj[nutrition]))
{nutritionObj[nutrition] = nutritionObj[nutrition] * ratio}
};
return nutritionObj
}
!isNaN('hi')
!isNaN(10)
smoothie1100g = calculateServing(smoothie1)