用js计算人体胖瘦
<script type="text/javascript"> var weight=prompt("请输入你体重(公斤)~"); var height=prompt("请输入你的身高(米)~"); getLast(weight,height); function getLast(weight,height){ setTimeout(function(){ var last=weight/(height*height); function getOkValue(last){ var weightOk; var heightOk; if(last <18){ weightOk=18*height*height; heightOk=Math.sqrt(weight/18) ; }else if(last>25){ weightOk=25*height*height; weightOk=weight/25; } return "休重应增加"+(weightOk-weight)+"kg,或身高"+(heightOk-height)+"m方可回到正常值。" } if(last>=18 && last<=25){ alert("BMI值是"+last+",正常~"); }else if(last<18){ alert("BMI值是"+last+","+getOkValue(last)+"偏瘦呢,亲~"); }else if(last>25){ alert("BMI值是"+last+","+getOkValue(last)+"偏胖呢,亲~"); } },1000); } </script>