JavaScript学习笔记-If-else
It has been 1502 days since the last update, the content of the article may be outdated.
if clause
javascript
if () { |
e.g. judge the teenager
javascript
var age = 20; |
多重判断
javascript
if () { |
e.g.
javascript
var age = 3; |
以及嵌套用法
javascript
var age = 3; |
javascript
var s = '123'; |
JavaScript把null、undefined、0、NaN和空字符串''
视为false,其他值一概视为true,因此上述代码条件判断的结果是true。
exercise
小明身高1.75,体重80.5kg。请根据BMI公式(体重除以身高的平方)帮小明计算他的BMI指数,并根据BMI指数:
- 低于18.5:过轻
- 18.5-25:正常
- 25-28:过重
- 28-32:肥胖
- 高于32:严重肥胖
javascript
var height = parseFloat(prompt('请输入身高(m):')); |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment