document.querySelector('.check').addEventListener('click', function () { };
I really would like the enter key to function exactly the same as a click on div.check –
I found the following online, however VS Code indicates that ‘key’ is depreciated.
It’s just a number guessing game. I would just like the enter key to also check the player’s guess, same as clicking the check button. You can look over everything on this codepen
document
.querySelector('.guess')
.addEventListener(
'keydown', (event) => {
// if not 'enter key' just exit here
if (event.keyCode !== 13) return
console.log(event.target.value)
})
document.querySelector('.check').addEventListener('click', function () {
checker();
});
// Runt the check function when 'Enter' is hit
document.querySelector('.guess').addEventListener('keydown', event => {
if (event.keyCode !== 13) return console.log(event.target.value);
checker();
});
So how would I combine these two listeners for dryer code?