【心得3】09/28
今天上半堂課老師開了數個同學寫作業的例子,看到了很多不同的想法,有助於啟發不同的邏輯思考,印象最深刻的是用「餘數」的寫法,是老師上次提示的寫法,很簡潔又有效率。 function myfunction ( x ) { i = ( i + x + cars . length ) % cars . length ; document . getElementById ( "demo" ). innerHTML = '<img src="' + cars [ i ] + ' " height=300px" alt="Seal">' } 自己的寫法是將「next」與「prev」個用一個函數控制。 function next () { i ++; if ( i == cars . length ) { i = cars . length - 1 ; } document . getElementById ( "demo" ). innerHTML = '<img src="' + cars [ i ] + ' " height=300px" alt="Seal">' } function pre () { i --; ...