Lab 25: Key Sequence Detection
Link to Lab 25:
While this lab may look simple, the real magic occurs in the console log of the lab. As the website says, the secret password is pizza. When you look at the console while typing on the website, you will see the characters you type appear. Once you type the letters that spell out pizza in order, then the ding dong text will appear in the console log. The JavaScript is very short and the following code is about 90% of the total JavaScript needed for this lab:
| const secretCode = 'pizza' | |
| 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'); | |
| } | |
| console.log(pressed); | |
| }) This code actually orchestrates that a ding ding texts will appear after you type pizza |

Comments
Post a Comment