Putting it in a function is a good idea.
You should open the browser console and see what the error was. That will help you fix it. Really take care and time to read and understand whatever the error is. Pasting the error into a search engine will help. You can find the developer console in the developer tools menu in your browser.
The freeCells
array is only available inside the generateMap
function. You will need to make it available outside if you want to use it outside, e.g. Game.freeCells = freeCells
.
You could then pick a random cell like this: ROT.RNG.getItem(Game.freeCells)
.
Good luck!