JS work and fixes

Shifted variable declaration position in order to put them in the proper
scope. Added function to track number of items left and fixed getItem to
properly reset the input field after retrieving the input