fixed creating function in loop jshint error