forked from christopherjereza/food-buddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversions.js
37 lines (35 loc) · 1.2 KB
/
conversions.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
/**
* File containing conversions from various units of measurement to grams.
* @author Unity
*/
/**
* Convert a quantity and unit to grams
* RETURN TYPE: float
*/
function getGrams(quantity, unit) {
if (unit === 'ounces' || unit === 'ounce') {
return quantity * 28.3495;
} else if (unit === 'grams' || unit === 'gram') {
return quantity;
} else if (unit === 'fluid ounces' || unit === 'fluid ounce') {
return quantity * 29.5735296875;
} else if (unit === 'pounds' || unit === 'pound') {
return quantity * 453.592;
} else if (unit === 'cups' || unit === 'cup') {
return quantity * 236.5882375;
} else if (unit === 'tablespoons' || unit === 'tablespoon') {
return quantity * 14.7867648437
} else if (unit === 'teaspoons' || unit === 'teaspoon') {
return quantity * 4.92892161457;
} else if (unit === 'liters' || unit === 'liter') {
return quantity * 1000;
} else if (unit === 'quarts' || unit === 'quart') {
return quantity * 946.35295;
} else if (unit === 'gallons' || unit === 'gallon') {
return quantity * 3785.4118;
}
else {
return quantity;
}
}
exports.getGrams = getGrams;