refactor javascript from html into a custom js file