I'm currently working on creating a game similar to Wordle, but I've hit a roadblock when it comes to filtering out only the alphabet keys as valid keyboard inputs for the game.
Within my Keyboard container, I have rows of keys and a JavaScript file that I can't seem to progress in:
// Keyboard
// Listen for key being released
let key_codes = [81,87,69,82,84,89,85,73,79,80,
65,83,68,70,71,72,74,75,76,
13,90,88,67,86,66,78,77,8];
document.addEventListener('keyup', (e) => {
if (e.keyCode in key_codes) {
console.log(e.keyCode);
}
});
I've compiled a list of acceptable keycodes for the game and attempted to set up an event listener to monitor key releases. However, when I check 'if (e.keyCode in key_codes)', I'm not getting any output despite expecting one.
I've verified the types of list elements and keyCodes (they match), and even tried printing 'e.keyCode' before the if statement, which correctly displays the pressed key. Despite this, I can't seem to identify what's causing the issue.
There might be something simple I'm overlooking here, but unfortunately, I haven't been able to solve it yet.