JavaScript uses lots of different types of brackets which must all be closed, and if they aren't, then your code is in trouble!
Select the type of bracket that you are interested in. Paste the code into the first box and click on the button. It will reproduce the code, but put a number by each bracket. This goes up and down with the nesting. Check that the last closed curly bracket in each function is 1.