-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
26 lines (20 loc) · 996 Bytes
/
index.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
const languages = ["en","fr"]
const lists = [
["Underweight", "Normal Weight", "Overweight", "Obesity", "Obesity", "Obesity"],
["Insuffisance pondérale", "Corpulence Normale", "Surpoids", "Obésité modérée", "Obésité sévère", "Obésité mordbide ou massive"]
]
const chooseAdjs = lists[0]
module.exports = {
bmi: (height,weight) => {
if(isNaN(height) || isNaN(weight)) return console.error("ERR ! \n The height or weight isn't a number")
const bmi = Math.round(weight / (height * height) * 10) / 10
let str;
if(bmi < 18.5) str = chooseAdjs[0];
else if(18.5 <= bmi && bmi < 25) str = chooseAdjs[1];
else if( 25 <= bmi && bmi < 30) str = chooseAdjs[2];
else if( 35 <= bmi && bmi < 40) str = chooseAdjs[3];
else if(40 <= bmi) str = chooseAdjs[4];
return result = { bmi : bmi, adjective : str };
},
setLanguage: language => { if (languages.includes(language)) chooseAdjs = lists[languages.indexOf(language)] }
};