30daysJS-12 - Key Sequence Detection (KONAMI CODE)

这个很简单，主要是利用数组方法和 KeyboardEvent.key 。 const serctCode = 'star' const arr = [] const main = document . querySelector ( 'main' ) window . addEventListener ( 'keydown' , code ) function code ( e ){ const key = e . key console . log ( key ); arr . push ( key ) arr . splice ( - serctCode . length - 1 , arr . length - serctCode . length - 1 ) if ( arr . join ( '' ). includes ( serctCode )){ alert (…