# How to do the hit and freeze level

**URL:** <https://discourse.codecombat.com/t/how-to-do-the-hit-and-freeze-level/30582>\
**Category:** Level Help\
**Created:** [September 22, 2021, 6:23pm UTC](https://discourse.codecombat.com/t/how-to-do-the-hit-and-freeze-level/30582 "2021-09-22T18:23:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Student\_Suraj\_Soni](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/student_suraj_soni/32/24814_2.png) [@Student\_Suraj\_Soni](https://discourse.codecombat.com/u/Student_Suraj_Soni)\
**Post date:** [September 22, 2021, 6:23pm UTC](https://discourse.codecombat.com/t/how-to-do-the-hit-and-freeze-level/30582/1 "2021-09-22T18:23:11Z")

</div>

I dont understand how to keep still

# This function checks if the enemy is in your attack range.

def inAttackRange(enemy):  
distance = hero.distanceTo(enemy)  
# Almost all swords have attack range of 3.  
if distance \<= 3:  
return True  
else:  
return False

# Attack ogres only when they’re within reach.

while True:  
# Find the nearest enemy and store it in a variable.  
enemy = hero.findNearestEnemy()  
# Call inAttackRange(enemy), with the enemy as the argument  
# and save the result in the variable canAttack.  
inAttackRange(enemy)  
canAttack=  
# If the result stored in canAttack is True, then attack!  
if “true”:  
hero.attack(enemy)  
else:  
pass

---

<div class="post-metadata">

**Author:** ![Vanessa](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vanessa/32/33899_2.png) [@Vanessa](https://discourse.codecombat.com/u/Vanessa)\
**Post date:** [September 22, 2021, 6:43pm UTC](https://discourse.codecombat.com/t/how-to-do-the-hit-and-freeze-level/30582/2 "2021-09-22T18:43:10Z")

</div>

Welcome to the discourse @Student_Suraj_Soni! 🥳 before you continue please read [this topic](https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521) on how to post your code correctly.
