JS复习-04-循环、数组

循环

循环的四个要素:初始化、条件判断、执行代码、自身改变

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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值