[JavaScript] conditional judgment

Xiao Ming is 1.75 in height and weighs 80.5kg. Please help Xiao Ming calculate his BMI index according to the BMI formula (weight divided by the square of height), and according to the BMI index:

Below 18.5: Underweight
18.5-25: Normal
25-28: Overweight
28-32: Obese
Above 32: Severely obese
Use if…else… to judge and display the results:

'use strict';

var height = parseFloat(prompt('请输入身高(m):'));
var weight = parseFloat(prompt('请输入体重(kg):'));

bmi = weight / height 
console.log(bmi)
if (bmi > 32) {
    
    
    console.log('严重肥胖');
} else if (32 >= bmi > 28) {
    
    
    console.log('肥胖');
} else if (28 > bmi >= 25){
    
    
   console.log('过重');
} else if (25 > bmi >= 18.5){
    
    
   console.log('过重');
} else {
    
    
    console.log('过轻');
}

Guess you like

Origin blog.csdn.net/daxiangaifashi/article/details/123273938