-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmi.js
42 lines (36 loc) · 1.08 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
39
40
41
42
function calculate(){
let weight = document.getElementById("weight").value;
let height = document.getElementById("height").value;
let result = document.getElementById("result");
let ans = (weight / height ** 2).toFixed(2);
let blank = 0;
if(result != blank){
result.innerHTML = " ";
}
if(ans < 18.5){
result.innerHTML += "Your BMI is " + ans + ". You are underweight."
}
else if(ans > 24.9){
result.innerHTML += "Your BMI is " + ans + ". You are overweight."
}
else if(ans > 30){
result.innerHTML += "Your BMI is " + ans + ". You are obese."
}
else{
result.innerHTML += "Your BMI is " + ans + ". You are of normal weight."
}
if(weight == blank || height == blank){
alert("Please add your height or weight!")
result.innerHTML = "Your BMI is:" + " ";
}
}
function reset(){
let weight = document.getElementById("weight");
let height = document.getElementById("height");
weight.value = " ";
height.value = " ";
weight.placeholder = "0";
height.placeholder = "0";
let result = document.getElementById("result");
result.innerHTML = "Your BMI is:";
}