Discuss / JavaScript / 练习

练习

Topic source

行云一FZ

#1 Created at ... [Delete] [Delete and Lock User]
'use strict';

var height = parseFloat(prompt('请输入身高(m):'));
var weight = parseFloat(prompt('请输入体重(kg):'));
var bmi = (weight/(height^2));
if(isNaN(bmi)) {
alert("非法输入!!!");
return;
}
if (bmi>=32){
alert('BMI: '+bmi+'结果:'+'严重肥胖')}
else if(bmi>=28){
alert('BMI: '+bmi+'结果:'+'肥胖')}
else if(bmi>=25){
alert('BMI: '+bmi+'结果:'+'过重')}
else if(bmi>=18.5){
alert('BMI: '+bmi+'结果:'+'正常')}
else{
alert('BMI: '+bmi+'结果:'+'过轻')};

  • 1

Reply