# Dance-Off help? Look at my code please

**URL:** <https://discourse.codecombat.com/t/dance-off-help-look-at-my-code-please/10873>\
**Category:** Uncategorized\
**Created:** [March 13, 2017, 9:11pm UTC](https://discourse.codecombat.com/t/dance-off-help-look-at-my-code-please/10873 "2017-03-13T21:11:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Celanios](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/celanios/32/5890_2.png) [@Celanios](https://discourse.codecombat.com/u/Celanios)\
**Post date:** [March 13, 2017, 9:11pm UTC](https://discourse.codecombat.com/t/dance-off-help-look-at-my-code-please/10873/1 "2017-03-13T21:11:03Z")

</div>

```python
while True:
    friend = hero.findNearest(hero.findFriends())
    if friend:
        hero.moveXY(friend.pos.x, friend.pos.y - 6)

```

What’s wrong with my solution?  
Everything looks ok when executed, except at the last part when they are lined up in a straight line. One other “friend” who is not my dance partner takes my spot in line behind my dance partner and my hero is forced to the end of the line.

Not sure if that’s why it’s not completing, and if so how to solve it?

Everything looks ok until that point at the end. I don’t know what else could be wrong. Please help. Thank you!

---

<div class="post-metadata">

**Author:** ![\_TD\_RodYT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/_td_rodyt/32/6285_2.png) [@\_TD\_RodYT](https://discourse.codecombat.com/u/_TD_RodYT)\
**Post date:** [March 14, 2017, 1:18am UTC](https://discourse.codecombat.com/t/dance-off-help-look-at-my-code-please/10873/2 "2017-03-14T01:18:44Z")

</div>

findFriends returns an array. Either use a for loop to loop through the array or just this to find the nearest friend:

```python
    friend = hero.findNearest(hero.findFriends()[0])

```

---

<div class="post-metadata">

**Author:** ![Celanios](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/celanios/32/5890_2.png) [@Celanios](https://discourse.codecombat.com/u/Celanios)\
**Post date:** [March 14, 2017, 10:43pm UTC](https://discourse.codecombat.com/t/dance-off-help-look-at-my-code-please/10873/3 "2017-03-14T22:43:42Z")

</div>

Thanks for the assist.

I was able to solve this without using a For loop or [0] added to the original code.  
I also found a second solution with a For loop.

The main thing that I was missing in both solutions was the use of the DistanceTo method.
