# Hit and Freeze Javascript code problem

**URL:** <https://discourse.codecombat.com/t/hit-and-freeze-javascript-code-problem/11941>\
**Category:** Uncategorized\
**Created:** [July 12, 2017, 12:23am UTC](https://discourse.codecombat.com/t/hit-and-freeze-javascript-code-problem/11941 "2017-07-12T00:23:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![awwsoclose](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@awwsoclose](https://discourse.codecombat.com/u/awwsoclose)\
**Post date:** [July 12, 2017, 12:23am UTC](https://discourse.codecombat.com/t/hit-and-freeze-javascript-code-problem/11941/1 "2017-07-12T00:23:32Z")

</div>

Hello everyone.

I’m currently stuck on Hit and Freeze. This is my code. Can you tell me where I went wrong?  
edit: copied the wrong code:

```python
// You are trapped. Don't move, it'll be painful.

// This function checks if the enemy is in your attack range.
function inAttackRange(enemy) {
    var 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.
    var enemy = hero.findNearestEnemy();
    // Call inAttackRange(enemy), with the enemy as the argument
   var canAttack = inAttackRange(enemy);
    // and save the result in the variable canAttack.
    if (canAttack === true);
    hero.attack;
    // If the result stored in canAttack is true, then attack!
    
}

```

---

<div class="post-metadata">

**Author:** ![Mr-Borges](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/mr-borges/32/6499_2.png) [@Mr-Borges](https://discourse.codecombat.com/u/Mr-Borges)\
**Post date:** [July 12, 2017, 12:46am UTC](https://discourse.codecombat.com/t/hit-and-freeze-javascript-code-problem/11941/2 "2017-07-12T00:46:36Z")

</div>

Two problems:

> [@awwsoclose](#):
>
> ```python
> if (canAttack === true);
> hero.attack;
> 
> ```

You don’t want that semi-colon in your if statement, it is ending your if statement before the attack can happen. Also:

> [@awwsoclose](#):
>
> hero.attack;

Who are you attacking? 😉

---

<div class="post-metadata">

**Author:** ![awwsoclose](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@awwsoclose](https://discourse.codecombat.com/u/awwsoclose)\
**Post date:** [July 12, 2017, 12:59am UTC](https://discourse.codecombat.com/t/hit-and-freeze-javascript-code-problem/11941/3 "2017-07-12T00:59:10Z")

</div>

That fixed it! You, sir/madam, are awesome

---

<div class="post-metadata">

**Author:** ![Seojin\_Roy\_Lee](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/seojin_roy_lee/32/23539_2.png) [@Seojin\_Roy\_Lee](https://discourse.codecombat.com/u/Seojin_Roy_Lee)\
**Post date:** [July 12, 2017, 6:05pm UTC](https://discourse.codecombat.com/t/hit-and-freeze-javascript-code-problem/11941/4 "2017-07-12T18:05:35Z")

</div>

I think it is a sir.
