exercises javascript refactored