Your attackEnemy method might be the one causing the problem. I see that you have the variable Enemy declared globally which could be fine except that it only defines one enemy and never changes. Maybe put the variable inside the attackEnemy method.
Inside the while loop you call hero.attack(enemy) which is fine but its not the method you created above which would help you attack the enemy when called.
Id also like to add that you didnt have to consider this a bug. Typically any forum title with Help! in it will get attention.
In addition to Ty-Ler’s comments, the else statement in the attackEnemy function is superfluous. You already collect coins by calling the pickUpCoin function so you don’t need to include this there.
You create an attack function, but never call it. Also, if you include the definition of enemy in the attackEnemy function, your code can be very simple.
It looks like you have everything you need, you just need to straighten it up a bit. Attention to detail is essential.