In real-world programming, is it important to eliminate the error if the program still works, or could I just leave it at that?
If it is important, how can I solve this level without getting that error? The way I see it, after hero defeats the second enemy, the next hero.findNearestEnemy returns null, and the health of null can’t be determined. But I need that “health-check”, yeah?
no, you do not need the health-check. hero.findNearestEnemy() returns the closest living enemy to the hero. but if the enemy is dead before the hero even reaches the enemy, then the hero would say ‘but it’s dead!’ and it would move on. To prevent that from happening, add a while loop which just checks if the enemy exists. The most that could happen is that right before you’re in range, something else kills it, but it most likely won’t say anything.