Currently I am working on a simple math game where the user hits the enter key to submit the answer to the math question. But, when enter is pressed all the variables are reset and everything is wiped out.
I know that this is probably a common question, but I have yet to see this answered for someone not trying to use a search bar. I'm just using a number input. I just want to keep the page from reloading and use my function when enter is pressed. I am really looking just to get the answer with the enter button and not refresh my page.
HTML for answer collection:
<form align= "center" id = "form">
<input type ="number" id ="answer" value ="" autofocus>
</form>
Javascript code:
document.getElementById("answer").onkeydown = function (event){
if(problems != 0){
if(event.keyCode == 13){
//some code in here
}
}
}