rex-nutrition-calculator-_personal

We been doing different types of work about many things since we're in this school, and one of the thing we are doing is coding/programming. And this semester we are doing a project about nutrition calculating, and talking about calculating, coding is fast and convenient for most calculating so we decide to make a program and do what we need about the program this is the topic I will be talking about in this essay.

So just finish talking about what we are doing, now I will like to explain what my program does and you will know why coding is good and how efficient coding can be.(only if you know how to do it). Ok, so basically what my program does is simple, all it does is calculating, it help us calculate what we put in, for n example if we want to calculate how much protein is in a hamburger, all we gotta do is, find all the ingredients, and knowing how much protein is in each ingredient, before we get the answer about the protein or even other nutrition, you have to tell the computer what's the data, so that the computer can calculate with numbers program will do the math for us. It do sound easy and fast but to be honest, It wasn't that easy for me to finish this Let me tell you why it took so many times to learn and finish this(especially for me)

Let me tell you why is hard for me to finish this work. The answer is easy, it was just too complicated for me, it seems easy but there is a couple steps for you to do is not like just: find number→ give data → done. The real steps are: gather your list of ingredients → find the amount of protein per 100g for each ingredient → make a class to describe an Ingredient →write a function that can take this object and some amount in grams of the ingredient that returns how much protein is in that amount. and something like this. So it was a lot of steps, and because I made this already, I'm going to tell you what are all these steps are about and how does my program work. First I make a class, a class is for you to make objects and to form our nutrition, and the reason class can make an object is because there's a function in class called constructor, so actually the one that's really making the object is constructor. And when we finish making a class, we need to do calculations about our properties that we make in our class, after that we put the object into an array, we make a function for printing, this part is for us to make the computer print things that are easy for human to read, so It should not be like code and stuff, it should be like rice have 450g something like this, and after it prints out with the right data, and it's print out in a human readable way than we are done with this.

I believe everything is hard for a reason, this coding work is hard for me for sure, it took a lot of time for me to finish one piece of work, but for our teacher this is easy, and the reason for this is because, my teacher study about this for very long time, and I believe that he done struggle about these questions and problems a lot too, even though he knows well how to do all these coding that us(students) are doing he still does not stop learning. I feel like people have to do things harder and harder to get evolute and become better, so we should not stop learning new things and harder things so that we can really be better peoples. This work seems big and important it include math, science and programming I actually learn a lot of new things from this work.

The point for coding is to make things that could be easier easier, but before all that all you need to do, is learn. You gotta do more work now, to make future easier. As I learn more I know more clear about this, what I work hard two years before now, help's me with things that I will like to finish right now. Is fun and is hard to learn coding, but as soon as you know about it, congrats your life can probably be success. Coding is useful and it's probably what people are looking for in the future.

===protein calculator ===
function sumArray (inputArray) {
  let sum = 0;
  for (let i = 0; i < inputArray.length; i++) {
    sum = sum + inputArray[i]
  }
  return sum}

class Ingredient {
    constructor (name,amountInDish,ProteinAmount100g,CarbsAmount100g,FatAmount100g,FiberAmount100g,
 SodiumAmount100mg, CalciumAmount100mg, IronAmount100mg,VitaminDAmount100mg,CaloriesAmount100g)
    { this.name = name;
      this.amountInDish = amountInDish;
      this.ProteinAmount100g = ProteinAmount100g;
      this.CarbsAmount100g = CarbsAmount100g;
      this.FatAmount100g = FatAmount100g;
      this.FiberAmount100g = FiberAmount100g;
      this.SodiumAmount100mg = SodiumAmount100mg;
      this.CalciumAmount100mg = CalciumAmount100mg;
      this.IronAmount100mg = IronAmount100mg;
      this.VitaminDAmount100mg = VitaminDAmount100mg;
      this.CaloriesAmount100g = CaloriesAmount100g;
      this.calculatedProtein = undefined;
      this.calculatedCarbs = undefined;
      this.calculatedFat = undefined;
      this.calculatedFiber = undefined;
      this.calculatedSodium = undefined;
      this.calculatedCalcium = undefined;
      this.calculatedIron = undefined;
      this.calculatedVitaminD = undefined;
      this.calculatedCalories= undefined;
      this.calculatedPercentage=undefined;
     }}


 let allIngredient = [
new Ingredient ('nuts', 4.6, 0.9913, 2.27, 0.575, 12.5, 5.38, 0.11, 0, 1.3, 144),
new Ingredient ('almond milk',120, 0.48, 1.56, 1.2, 0.24, 86.4, 221, 0.36, 0, 20),
new Ingredient ('banana', 39, 0.43, 9, 0.12, 1.01, 0.4, 2, 0.12, 0, 88.7),
]

function calculatedSmoothie (IngredientObject){
//Protein
  IngredientObject.calculatedProtein = IngredientObject.ProteinAmount100g / 100 * IngredientObject.amountInDish
//Carbs
  IngredientObject.calculatedCarbs = IngredientObject.CarbsAmount100g / 100 * IngredientObject.amountInDish
//Fat
     IngredientObject.calculatedFat = IngredientObject.FatAmount100g / 100 * IngredientObject.amountInDish
//Fiber
      IngredientObject.calculatedFiber = IngredientObject.FiberAmount100g / 100 * IngredientObject.amountInDish
//Sodium
  IngredientObject.calculatedSodium = IngredientObject.SodiumAmount100mg / 100 * IngredientObject.amountInDish
//Calcium
    IngredientObject.calculatedCalcium = IngredientObject.CalciumAmount100mg / 100 * IngredientObject.amountInDish
//Iron
      IngredientObject.calculatedIron = IngredientObject.IronAmount100mg / 100 * IngredientObject.amountInDish
//VitaminD
    IngredientObject.calculatedVitaminD = IngredientObject.VitaminDAmount100mg / 100 * IngredientObject.amountInDish
//Calories
 IngredientObject.calculatedCalories = IngredientObject.CaloriesAmount100g / 100 * IngredientObject.amountInDish;
 return IngredientObject
}

//function nutritionPrinter (inputArray, totalAmount, Ingredients, totalProtein, totalCarb, totalFat, totalFiber, totalIron, totalSodium, totalCalcium, totalVitaminD, totalCalories) {
function nutritionPrinter (inputArray) {
  inputArray.forEach(i => {
      console.log("the ingredient name is",i.name);
      console.log("the ingredient amount is ",i.amountInDish);
      console.log("the amount of protein",i.ProteinAmount100g);
      console.log("the amount of carbs", i.CarbsAmount100g);
      console.log("the amount of fat",i.FatAmount100g);
      console.log("the amount of fiber",i.FiberAmount100g);
      console.log("the amount of iron",i.IronAmount100mg);
      console.log("the amount of sodium",i.SodiumAmount100mg);
      console.log("the amount of calcium",i.CalciumAmount100mg);
      console.log("the amount of vitaminD",i.VitaminDAmount100mg)
      console.log("the amount of Calories",i.CaloriesAmount100g)
      })
}

function totalNutrition (IngredientArray) {
  IngredientArray = IngredientArray.map(calculatedSmoothie)
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 allWeightValues = IngredientArray.map(o => o.amountInDish)
 //console.log(allWeightValues)
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)
  let totalWeight = sumArray (allWeightValues)
//nutritionPrinter (IngredientArray, totalProtein, totalCarb, totalFat, totalFiber, totalIron, totalSodium, totalCalcium, totalVitaminD,totalCalories)
nutritionPrinter (IngredientArray)
//console.log(allIngredient)
let nutritionObj =
{
  name:'smoothie',
  ingredients: IngredientArray,
  protein: totalProtein,
  carb: totalCarb,
  fat: totalFat,
  fiber: totalFiber,
  iron: totalIron,
  sodium: totalSodium,
  calcium: totalCalcium,
  vitaminD: totalVitaminD,
  calories: totalCalories,
  weight: totalWeight,
}
console.log('the name of this dish is ',  nutritionObj.name);
console.log('the total amount of protein is ', nutritionObj.protein);
console.log('the total amount of carb is ', nutritionObj.carb);
console.log('the total amount of fat is ', nutritionObj.fat);
console.log('the total amount of fiber is ', nutritionObj.fiber);
console.log('the total amount of iron is ', nutritionObj.iron);
console.log('the total amount of sodium is ', nutritionObj.sodium);
console.log('the total amount of calcium is ', nutritionObj.calcium);
console.log('the total amount of vitaminD is ', nutritionObj.vitaminD);
console.log('the total amount of calories is ', nutritionObj.calories);
console.log('the total amount of weight is ', nutritionObj.weight);
return nutritionObj
}


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)

===== output =====
smoothie1100g = calculateServing(smoothie1)
VM611:76 the ingredient name is empty
VM611:77 the ingredient amount is  300
VM611:78 the amount of protein 0.7
VM611:79 the amount of carbs 18.9
VM611:80 the amount of fat 1
VM611:81 the amount of fiber 4.2
VM611:82 the amount of iron 0.3
VM611:83 the amount of sodium 1.6
VM611:84 the amount of calcium 12.4
VM611:85 the amount of vitaminD 0
VM611:86 the amount of Calories 79
VM611:76 the ingredient name is empty
VM611:77 the ingredient amount is  350
VM611:78 the amount of protein 3.6
VM611:79 the amount of carbs 12.8
VM611:80 the amount of fat 5
VM611:81 the amount of fiber 0
VM611:82 the amount of iron 0
VM611:83 the amount of sodium 57
VM611:84 the amount of calcium 106
VM611:85 the amount of vitaminD 0
VM611:86 the amount of Calories 113
VM611:76 the ingredient name is empty
VM611:77 the ingredient amount is  725
VM611:78 the amount of protein 3.2
VM611:79 the amount of carbs 4.8
VM611:80 the amount of fat 3.3
VM611:81 the amount of fiber 0
VM611:82 the amount of iron 0
VM611:83 the amount of sodium 43
VM611:84 the amount of calcium 113
VM611:85 the amount of vitaminD 1.3
VM611:86 the amount of Calories 61
VM611:76 the ingredient name is empty
VM611:77 the ingredient amount is  0
VM611:78 the amount of protein 0
VM611:79 the amount of carbs 0
VM611:80 the amount of fat 0
VM611:81 the amount of fiber 0
VM611:82 the amount of iron 0
VM611:83 the amount of sodium 0
VM611:84 the amount of calcium 0
VM611:85 the amount of vitaminD 0
VM611:86 the amount of Calories 0
VM611:76 the ingredient name is empty
VM611:77 the ingredient amount is  150
VM611:78 the amount of protein 3.2
VM611:79 the amount of carbs 4.8
VM611:80 the amount of fat 3.3
VM611:81 the amount of fiber 0
VM611:82 the amount of iron 0
VM611:83 the amount of sodium 43
VM611:84 the amount of calcium 113
VM611:85 the amount of vitaminD 1.3
VM611:86 the amount of Calories 61
VM611:76 the ingredient name is empty
VM611:77 the ingredient amount is  200
VM611:78 the amount of protein 0.6
VM611:79 the amount of carbs 7.6
VM611:80 the amount of fat 0.2
VM611:81 the amount of fiber 0.4
VM611:82 the amount of iron 0.2
VM611:83 the amount of sodium 1
VM611:84 the amount of calcium 7
VM611:85 the amount of vitaminD 0
VM611:86 the amount of Calories 30
VM611:76 the ingredient name is empty
VM611:77 the ingredient amount is  300
VM611:78 the amount of protein 0.5
VM611:79 the amount of carbs 13
VM611:80 the amount of fat 0.1
VM611:81 the amount of fiber 1.4
VM611:82 the amount of iron 13
VM611:83 the amount of sodium 0.3
VM611:84 the amount of calcium 1
VM611:85 the amount of vitaminD 0
VM611:86 the amount of Calories 50
VM611:76 the ingredient name is nuts
VM611:77 the ingredient amount is  4.6
VM611:78 the amount of protein 0.9913
VM611:79 the amount of carbs 2.27
VM611:80 the amount of fat 0.575
VM611:81 the amount of fiber 12.5
VM611:82 the amount of iron 0
VM611:83 the amount of sodium 5.38
VM611:84 the amount of calcium 0.11
VM611:85 the amount of vitaminD 1.3
VM611:86 the amount of Calories 144
VM611:76 the ingredient name is almond milk
VM611:77 the ingredient amount is  120
VM611:78 the amount of protein 0.48
VM611:79 the amount of carbs 1.56
VM611:80 the amount of fat 1.2
VM611:81 the amount of fiber 0.24
VM611:82 the amount of iron 0.36
VM611:83 the amount of sodium 86.4
VM611:84 the amount of calcium 221
VM611:85 the amount of vitaminD 0
VM611:86 the amount of Calories 20
VM611:76 the ingredient name is banana
VM611:77 the ingredient amount is  39
VM611:78 the amount of protein 0.43
VM611:79 the amount of carbs 9
VM611:80 the amount of fat 0.12
VM611:81 the amount of fiber 1.01
VM611:82 the amount of iron 0.12
VM611:83 the amount of sodium 0.4
VM611:84 the amount of calcium 2
VM611:85 the amount of vitaminD 0
VM611:86 the amount of Calories 88.7
VM611:131 the name of this dish is  smoothie
VM611:132 the total amount of protein is  46.1892998
VM611:133 the total amount of carb is  203.18642
VM611:134 the total amount of fat is  51.58824999999999
VM611:135 the total amount of fiber is  18.8569
VM611:136 the total amount of iron is  40.7788
VM611:137 the total amount of sodium is  687.5334799999998
VM611:138 the total amount of calcium is  1679.9350599999998
VM611:139 the total amount of vitaminD is  11.4348
VM611:140 the total amount of calories is  1441.467
VM611:141 the total amount of weight is  2188.6
  • rex-nutrition-calculator-_personal.txt
  • Last modified: 2022/06/22 20:11
  • by howard.lee