-
Notifications
You must be signed in to change notification settings - Fork 86
/
BMI.js
38 lines (29 loc) · 1.06 KB
/
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
35
36
37
38
const form=document.querySelector('form')
// this usecase will give you empty value
// const height= parseInt(document.querySelector('#height').value)
form.addEventListener('submit',function(e){
e.preventDefault();
const height= parseInt(document.querySelector('#height').value)
const weight= parseInt(document.querySelector('#weight').value)
const results= (document.querySelector('#results'))
if (height===""|| height<0 || isNaN(height)) {
results.innerHTML="Please give a valid height"
}
else if (weight===""|| weight<0 || isNaN(weight)) {
results.innerHTML="Please give a valid weigth"
}
else{
const bmi=(weight/((height*height)/10000)).toFixed(2)
//show the result
results.innerHTML=`<span>${bmi}</span>`
if (bmi<18.6) {
results.innerHTML=`<span>${bmi} <br>OMG Your Under weight</span>`
}
else if(bmi>18.6 && bmi<24.9){
results.innerHTML=`<span> ${bmi} <br>Congrats Your fit & fine</span>`
}
else{
results.innerHTML=`<span> ${bmi} <br>OMG Your Over weight</span>`
}
}
})