Converted electricity.js.coffee to pure javascript