循环
循环的四个要素:初始化、条件判断、执行代码、自身改变
var init=0
while (init<3){
console.log(init)
init++
}
数组
是一个复杂数据类型,按照索引0~正无穷排序
var arr=[‘hello’, 1,2]
三元运算符
对if else的简写:条件?成立执行:不成立执行
练习
1.输入月份显示当月天数
var month=10
var year=2019
switch(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
console.log('本月有31天')
break
case 4:
case 6:
case 9:
case 11:
console.log('本月有30天')
break
case 2:
(year%4===0 && year%100!==0 ||year%400===0)?
console.log('29'):
console.log('28')
break
default:
console.log('输入不正确')
2.判断月份是第几天
var year=2016
var month=5
var day=12
var date=0
var arr=[31,28,31,30,31,30,31,31,30,31,30,31]
if(year%4===0 && year%100!==0 ||year%400==0){
arr[1]=29
}
while(month>1){
console.log(month)
date=date+arr[month-2]
month--
}
date=date+day