Enter Button To Submit Info

O-hi!

I’ve been playing around with the Random Number Guessing Game found on the MDN (link to the code - learning-area/number-guessing-game.html at master · mdn/learning-area · GitHub) website and would like to add a function to submit information in the field by tapping the ‘Enter’ button instead of having to manually click on the ‘Submit’ button. So far I’ve found the code below with certain variations as a solution. Only problem is, it doesn’t seem to fix the issue for me. Here’s the code I’ve found online:

let input = document.getElementById(“myInput”);
input.addEventListener(“keyup”, function(event) {
if (event.keyCode === 13) {
event.preventDefault();
document.getElementById(“myBtn”). click();
}
});

If anyone knows a good way to do this, please do let me know as it’s a function I’d like to implement into every site I build. Having to manually click on a submit-like button every time sucks.

document.getElementById("myInput");, I don’t see an element with id myInput anywhere?

same is very likely true for myBtn