Javascript can't count brackets