Skip to content

Commit 7f09d1d

Browse files
committed
key sequance listener exercise
1 parent 12cae66 commit 7f09d1d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Key Sequence Detection/index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Key Detection</title>
6+
<script type="text/javascript" src="http://www.cornify.com/js/cornify.js"></script>
7+
</head>
8+
<body>
9+
<script>
10+
const pressed = [];
11+
const secretCode = "katej";
12+
window.addEventListener("keyup", (e)=>{
13+
console.log(e.key);
14+
pressed.push(e.key);
15+
pressed.splice(-secretCode.length - 1, pressed.length - secretCode.length)
16+
console.log(pressed);
17+
18+
if(pressed.join('').includes(secretCode)){
19+
console.log("ding ding");
20+
}
21+
});
22+
23+
//when someone inputs a certain sequnece of code , something happens
24+
</script>
25+
</body>
26+
</html>

0 commit comments

Comments
 (0)