Several concerns

Of course this was not the full solution (only 15% of your code) and so much failures and chaos!!!

First —> REWRITE your code giving it a much better STRUCTURE.
Second → use more → CONSOLE-LOGS to inspect and understand your own code better.

You will have to modify and edit a lot, to get the result how it should be.