-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (22 loc) · 1.06 KB
/
script.js
File metadata and controls
26 lines (22 loc) · 1.06 KB
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
let form = document.querySelector('form');
form.addEventListener('submit', function(e){
e.preventDefault();
let height = parseInt(document.getElementById('height').value);
let weight = parseInt(document.getElementById('weight').value);
let result = document.getElementById('result');
result.style.display = 'block';
if ((height === '') || (height < 0) || (isNaN(height)) ) {
result.innerHTML = `${height} is Invalid Height <br/> Please provide valid Height`;
} else if ((weight === '') || (weight < 0) || (isNaN(weight)) ) {
result.innerHTML = `${weight} is Invalid Weight <br/> Please provide valid Weight`;
} else {
let bmi = (weight / ((height * height) / 10000)).toFixed(2);
if (bmi < 18.6) {
result.innerHTML = `BMI = ${bmi} <br/> This is Under Weight`;
} else if (bmi > 24.9){
result.innerHTML = `BMI = ${bmi} <br/> This is Over Weight`;
} else if(bmi > 18.6 && bmi < 24.9){
result.innerHTML = `BMI = ${bmi} <br/> This is Normal Weight`;
}
}
});