練習1-1:<br>JS

(4)判斷【星期,nowW】

if(nowW==0){nowW = '日'}
if(nowW==1){nowW = '一'}
if(nowW==2){nowW = '二'}
if(nowW==3){nowW = '三'}
if(nowW==4){nowW = '四'}
if(nowW==5){nowW = '五'}
if(nowW==6){nowW = '六'}
if ( nowW==0 ) { nowW = '日';	}
	 else if ( nowW==1 ) { nowW = '一';} 
	 else if ( nowW==2 ) { nowW = '二';} 
	 else if ( nowW==3 ) { nowW = '三';} 
	 else if ( nowW==4 ) { nowW = '四';} 
	 else if ( nowW==5 ) { nowW = '五';} 
	 else  { nowW = '六';} 

 

switch( nowW ){
	case 0: nowW = '日'; 
	case 1: nowW = '一'; 
	case 2: nowW = '二'; 
	case 3: nowW = '三'; 
	case 4: nowW = '四'; 
	case 5: nowW = '五'; 
	case 6: nowW = '六'; 
}

 

switch( nowW ){
	case 0: nowW = '日'; break;
	case 1: nowW = '一'; break;
	case 2: nowW = '二'; break;
	case 3: nowW = '三'; break;
	case 4: nowW = '四'; break;
	case 5: nowW = '五'; break;
	case 6: nowW = '六'; break;
}
var weekN = ['日','一','二','三','四','五','六','日'];
for (i=0; i<weekN.length; i++){
	if( nowW==i ){ nowW = weekN[i]; }
}

參考連結1參考連結2

參考連結1參考連結2

For循環

參考連結1參考連結2