Trying to put sections of code in correct order

Copy and pasting from my working JSFiddle