Your code is locking up because you never release control. JavaScript is a single-threaded language. If you want to allow something else to happen, you need to release control by allowing your function to return. If you want to do something repeatedly, you can use setInterval
to run code every certain number of milliseconds, or requestAnimationFrame
which adds your function call to the event loop and allows other things like the UI to continue to work even though your function gets called repeatedly to update whatever it is you need it to do. There is some good documentation available to you if you want to weigh your options.
solved New to javascript, Is there a way to create an idle game?