-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmi.js
37 lines (17 loc) · 798 Bytes
/
bmi.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
// Write function bmi that calculates body mass index (bmi = weight / height ^ 2).
// if bmi <= 18.5 return "Underweight"
// if bmi <= 25.0 return "Normal"
// if bmi <= 30.0 return "Overweight"
// if bmi > 30 return "Obese"
function bmi(weight, height) {
const bmi = weight / (height**2);
if(bmi <= 18.5) return "Underweight";
if(bmi <= 25.0) return "Normal";
if(bmi <= 30.0) return "Overweight";
return "Obese";
}
const bmi2 = (w, h, bmi = w/h/h) => bmi <= 18.5 ? "Underweight" :
bmi <= 25 ? "Normal" :
bmi <= 30 ? "Overweight" : "Obese";
const bmi3 = (w, h) => (w = w / h / h) > 30 ? 'Obese' : w > 25 ? 'Overweight' : w > 18.5 ? 'Normal' : 'Underweight';
console.log(bmi(80, 1.80));