-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculate-bmi.js
More file actions
52 lines (29 loc) · 925 Bytes
/
calculate-bmi.js
File metadata and controls
52 lines (29 loc) · 925 Bytes
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
//8 Kyu
//Calculate BMI
//Fundamentals
// Write function bmi that calculates body mass index
// (bmi = weight / height2).
// if bmi <= 18.5 return "Underweight"
// if bmi <= 25.0 return "Normal"
// if bmi <= 30.0 return "Overweight"
// if bmi > 30 return "Obese"
//Solution I
function bmi(weight, height) {
//calculate bmi
let bmi = weight / height**2
//use condiional statement to return the correct str
if(bmi <= 18.5) return "Underweight"
if(bmi <= 25.0) return "Normal"
if(bmi <= 30.0) return "Overweight"
if(bmi > 30.0) return "Obese"
}
//Parameters
//num1, num2 -> num1 = weight, num2 = height. bmi = weight / height^2
//never emtpy, not null, both only always nums
//Return
//str-> if bmi <= 18.5 return "Underweight"
// if bmi <= 25.0 return "Normal"
// if bmi <= 30.0 return "Overweight"
// if bmi > 30 return "Obese"
//Example
//console.log(bmi(50, 1.80), "Underweight")