I am struggling to create my first event listener for the submit button that should respond to both a click and an enter key press. Currently, it is not working for either event, and I am unsure why. I do not intend to send any data to another page; I simply want it to trigger other actions.
var domStrings = {
submit: document.querySelector('#submit')
}
var checker = function() {
var lcase;
domStrings.submit.addEventListener("click", function(e) {
e.preventDefault();
console.log('form submitted');
lCase = guess.value.toLowerCase();
turnCounter++;
if (entryField.value.includes(lCase)) {
for (i = 0; i < entryField.value.length; i++) {
if (lCase === entryField.value[i]) {
retainAndReplace(domStrings.word.textContent, i, lCase)
}
}
} else {
//tell user they're wrong
wrong.style.visibility = 'visible';
wrong.classList.add('.fade-out-wrong')
setTimeout(invisibleWrong, 4000);
guessCounter--;
if (guessCounter < 1) {
//display game over
over.style.display = 'inline'
chances.textContent = `Guesses remaining: 0`;
wrong.style.display = 'none';
//hide dashes
word.style.display = 'none'
} else {
chances.textContent = `Guesses remaining: ${guessCounter}`;
}
}
})
}
checker()
<input type = 'text' id = 'guess' placeholder = 'Letter Guess' maxlength = '1'>
<button type = 'submit' id ='submit'> Submit </button>