Update script.js

refactoring