-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFood.js
58 lines (42 loc) · 1.51 KB
/
Food.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class Food{
constructor(ingredient, dietaryInformation, nutritionalInformation){
this.ingredient = ingredient;
this.dietaryInformation = dietaryInformation;
this.nutritionalInformation = nutritionalInformation
}
getScaledNutrition(ingredient){
var equals = EQUALS[ingredient.name];
if(equals.canChangeUnit(this.ingredient.unit, ingredient.unit)){
newIngredient = equals.changeUnit(ingredient, this.ingredient.unit);
var scaleFactor = ingredient.amount / this.ingredient.amount;
return this.nutritionalInformation.scale(scaleFactor);
}
else{
return new NutritionInfo();
}
}
satisfiesDietaryRequirements(requirements){
for(let i = 0; i < requirements.length; i++){
if(!this.dietaryInformation.includes(requirements[i])){
return false;
}
}
return true;
}
}
function loadFood(foodList, lastFood, endFunction){
var thisFood = lastFood + 1
if(thisFood == foodList.length){
endFunction();
}
else{
var food = foodList[thisFood];
var link = "foods/" + food.name + ".js";
var script = document.createElement('script');
script.src = link;
script.onload = ()=>(loadFood(foodList, thisFood, endFunction));
script.onerror = ()=>(loadFood(foodList, thisFood, endFunction));
document.getElementsByTagName('head')[0].appendChild(script);
}
}
var FOODS = {};