refactor Javascript for multiple animals and races