-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
24 lines (22 loc) · 918 Bytes
/
script.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
const hInput = document.getElementById('height');
const wInput = document.getElementById('weight');
const button = document.getElementById('calc');
const result = document.getElementById('result');
button.addEventListener('click', () => {
if (hInput.value == '' || wInput.value == '') {
alert('Enter your height and your weight');
} else {
let height = hInput.value;
let weight = wInput.value;
let BMI = (weight / ((height * height) / 10000)).toFixed(2);
if (BMI < 18.5) {
result.innerText = `Your BMI is ${BMI} and you are underweight`;
} else if (BMI >= 18.5 && BMI <= 24.9) {
result.innerText = `Your BMI is ${BMI} and your weight is healthy`;
} else if (BMI >= 25 && BMI <= 29.9) {
result.innerText = `Your BMI is ${BMI} and you are overweight`;
} else {
result.innerText = `Your BMI is ${BMI} and you are obese`;
}
}
});