-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
69 lines (43 loc) · 2.04 KB
/
main.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
59
60
61
62
63
64
65
//variables used declared before function.
let feet,inches,constant,weight, realHeight, result, finalHeight, finalResult;
// In this function I am performing the whole calculation
const bmiOperation = () => {
//height (feet) input variable
feet = document.getElementById('feet').value;
inches = document.getElementById('inches').value;
finalHeight = feet*12 + +inches;
// weight input variable
weight = document.getElementById('weight').value;
constant = 703;
realHeight = Math.pow(finalHeight, 2);
result = (constant * weight/realHeight) ;
// rounded with *10/10 to show first decimal of the final result.
finalResult = Math.round(result*10)/10;
// console.log(finalResult)
document.getElementById('result').innerHTML = finalResult
const bmi = finalResult
if ( bmi <= 18.5 ) {
document.getElementById('advice').innerHTML = ranges[0]
} else if ( bmi <= 24.9) {
document.getElementById('advice').innerHTML = ranges[1]
} else if ( bmi <= 29.9) {
document.getElementById('advice').innerHTML = ranges[2]
} else if ( bmi <= 100) {
document.getElementById('advice').innerHTML = ranges[3];
} else if (bmi !== Number){
document.getElementById('result').innerHTML = errorMessages[0];
document.getElementById('advice').innerHTML = '';
}
//Values can't be zero or negative integers
if (bmi <= 0) {
document.getElementById('result').innerHTML = errorMessages[1];
document.getElementById('advice').innerHTML = ''
}
}
//BMI advice statements
const ranges = ["You are underweight. Reach out to a health proffesional to discuss more about your nutrition habits.",
"You are healthy, your BMI stands in a good position. Keep your good diet and exercise habits up.",
"You are overweight. Try to stick to better eating habits and exercises to reduce your BMI.",
"You are obese. Reach out to a health proffesional to discuss more about how to reduce your BMI. " ]
const errorMessages = ["Please enter your information correctly.",
" Something was wrong with your inputs. Try again." ]