Key Sequence Detection
wesbos라는 단어가 완성되면 이벤트가 실행된다.
const pressed = [];
const secretCode = 'wesbos';
window.addEventListener('keyup', (e) => {
// console.log(e.key);
pressed.push(e.key);
pressed.splice(-secretCode.length - 1, pressed.length - secretCode.length);
if(pressed.join('').includes(secretCode)) {
console.log('DING DING!');
cornify_add();
}
console.log(pressed);
});
'JavaScript30 Challenge' 카테고리의 다른 글
[JavaScript30] Day 14 (0) | 2020.06.11 |
---|---|
[JavaScript30] Day 13 (0) | 2020.06.08 |
[JavaScript30] Day 11 (0) | 2020.05.04 |
[JavaScript30] Day 10 (0) | 2020.04.27 |
[JavaScript30] Day 9 (0) | 2020.04.26 |