Inputs, Forms and Keys
A text box's current contents are input.value, and it is always text, even for type="number". Convert it with Number() before any math. Listen for the input event to react to every keystroke, or change to react when the person has finished.
Forms fire a submit event when someone presses Enter or a submit button. The browser's own response is to send the form somewhere and reload the page, which would wipe out your app. event.preventDefault() cancels that, so your code can handle it instead.
Keys fire keydown. event.key is the character or the key's name, such as "Escape" or "Enter"; event.code names the physical key, such as "Space". Shortcuts listen on the whole document, and they should ignore keys typed into a box, or typing a space in a name would also pause your timer: if (event.target.matches("input, textarea")) return;
Mark this lesson complete
Signed in, your progress follows you to every device.