1. There are two functions called "distance" and they're identical. Only the outermost appears to be needed.
2. As written, the game places variable and function names into the global scope. It doesn't matter for this game, but will be a problem for larger games. One idea would be to use the Immediately Invoked Function Expression (IIFE) pattern [1]. Another would be to take advantage of ES6 modules[2] (<script type="module">) to limit variable scope.
[1] https://developer.mozilla.org/en-US/docs/Glossary/IIFE
[2] https://www.contentful.com/blog/2017/04/04/es6-modules-suppo...