Fix jshint error by moving if statement