# \[SOLVED\] Dance-off Please help JS

**URL:** <https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906>\
**Category:** Level Help\
**Created:** [June 6, 2018, 1:40pm UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906 "2018-06-06T13:40:49Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![chichi\_King](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chichi_king/32/8247_2.png) [@chichi\_King](https://discourse.codecombat.com/u/chichi_King)\
**Post date:** [June 6, 2018, 1:40pm UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/1 "2018-06-06T13:40:49Z")

</div>

```python
// Move in sync with your dance partner to impress Pender Spellbane.
while(true) {
    var friend = hero.findNearest(hero.findFriends());
      if(hero.distanceTo(friend) < 7) {
        hero.moveXY(friend.pos.x, friend.pos.y + 6);
    }
}

```

Hey guys. Can someone please tell me what am I doing wrong here?  
Thanks!

---

<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:** [June 6, 2018, 9:37pm UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/2 "2018-06-06T21:37:06Z")

</div>

that doesn’t complete the level.

---

<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:** [June 6, 2018, 9:40pm UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/3 "2018-06-06T21:40:07Z")

</div>

or, take out line number 4.

---

<div class="post-metadata">

**Author:** ![chichi\_King](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chichi_king/32/8247_2.png) [@chichi\_King](https://discourse.codecombat.com/u/chichi_King)\
**Post date:** [June 7, 2018, 4:20am UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/4 "2018-06-07T04:20:38Z")

</div>

I know.  
I have no idea what to do.

---

<div class="post-metadata">

**Author:** ![chichi\_King](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chichi_king/32/8247_2.png) [@chichi\_King](https://discourse.codecombat.com/u/chichi_King)\
**Post date:** [June 7, 2018, 1:31pm UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/5 "2018-06-07T13:31:29Z")

</div>

Seriously. Somebody?

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [June 7, 2018, 1:41pm UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/6 "2018-06-07T13:41:29Z")

</div>

You have to put `var friend = hero.findNearest(hero.findFriends())`; outside the while-true loop, that’s it.

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [June 7, 2018, 1:49pm UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/7 "2018-06-07T13:49:29Z")

</div>

I like your profile picture, it’s cool.

---

<div class="post-metadata">

**Author:** ![chichi\_King](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chichi_king/32/8247_2.png) [@chichi\_King](https://discourse.codecombat.com/u/chichi_King)\
**Post date:** [June 7, 2018, 1:54pm UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/8 "2018-06-07T13:54:13Z")

</div>

Man! Thank you!! 🙂  
But can you explain why it wasn’t working with `variable` inside the loop?

Ahaha. Fan of Matrix?

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [June 7, 2018, 2:49pm UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/9 "2018-06-07T14:49:44Z")

</div>

It’s because it carries on getting looped so when you were near another person who wasn’t you dance partner your nearest friend became that person and you went to their yPos + 6.  
I haven’t watched the Matrix but I want to, I’ve seen the lobby scene and the scene where he dodges the bullets and gets shot in the legs. 😭 But yeah, I wanna watch it a lot I also want to watch the x-files.

---

<div class="post-metadata">

**Author:** ![chichi\_King](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chichi_king/32/8247_2.png) [@chichi\_King](https://discourse.codecombat.com/u/chichi_King)\
**Post date:** [June 7, 2018, 3:02pm UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/10 "2018-06-07T15:02:30Z")

</div>

Makes sence. Thanks o lot!!

What stops you from it? Go and watch 🙂

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [June 7, 2018, 3:08pm UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/11 "2018-06-07T15:08:37Z")

</div>

I will watch it I think but we don’t have it and I’ve only just recently started to want to watch it but hopefully I’ll be able to get it from a library or something like that.

---

<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:** [June 7, 2018, 9:00pm UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/12 "2018-06-07T21:00:16Z")

</div>

what exactly do you need help with?

---

<div class="post-metadata">

**Author:** ![chichi\_King](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chichi_king/32/8247_2.png) [@chichi\_King](https://discourse.codecombat.com/u/chichi_King)\
**Post date:** [June 8, 2018, 5:55am UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/13 "2018-06-08T05:55:40Z")

</div>

I’ve solved it already. Thanks.

---

<div class="post-metadata">

**Author:** ![gcxyshiyu](https://avatars.discourse-cdn.com/v4/letter/g/7cd45c/32.png) [@gcxyshiyu](https://discourse.codecombat.com/u/gcxyshiyu)\
**Post date:** [January 1, 2019, 10:01am UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/14 "2019-01-01T10:01:50Z")

</div>

Mod edit: Please do not request solutions. The purpose of this board is to assist people with their code. Simply providing solutions is counter productive to the learning process. There are many people here willing and able to assist you with your code but we do not just give the answers. Thanks.

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [January 1, 2019, 11:22am UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/15 "2019-01-01T11:22:39Z")

</div>

Sorry @gcxyshiyu , no-one is allowed to give working code to someone else.

If you’re having trouble with this level, do these things:

- Make a new topic with a clear title stating your problem. For example: I’m having trouble with the level Dance-off.
- Post your code formatted as stated in the [https://discourse.codecombat.com/faq](https://discourse.codecombat.com/faq)
- State what you’re having difficulties with.

Optional:

- Post a screenshot of the screen and you’re equipment.
- Give a direct link to the level, for example: [https://codecombat.com/play/level/example-level](https://codecombat.com/play/level/example-level)

Thanks,  
🦁 🦁 🦁

---

<div class="post-metadata">

**Author:** ![3nterpris3](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/3nterpris3/32/11441_2.png) [@3nterpris3](https://discourse.codecombat.com/u/3nterpris3)\
**Post date:** [February 16, 2020, 2:35am UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/16 "2020-02-16T02:35:30Z")

</div>

Your character’s Y position may be above or below your dance partner, or the person you are going to share the X position with all along. You only prepared for if your Y position is bigger than your dance partner’s one.

---

<div class="post-metadata">

**Author:** ![Cedar](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cedar/32/29302_2.png) [@Cedar](https://discourse.codecombat.com/u/Cedar)\
**Post date:** [June 12, 2022, 3:13pm UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/17 "2022-06-12T15:13:12Z")

</div>

I am having trouble with dance off also, I can’t figure out how to link my characters movements to my partners.

```python
# Move in sync with your dance partner to impress Pender Spellbane.
while True:
    friends = hero.findFriends()
    
    friend = hero.findNearest(friends)
    offset = hero.distanceTo(friend)
    hero.move(friend.pos + offset)

```

---

<div class="post-metadata">

**Author:** ![moonwatcher348](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/moonwatcher348/32/24126_2.png) [@moonwatcher348](https://discourse.codecombat.com/u/moonwatcher348)\
**Post date:** [June 12, 2022, 5:05pm UTC](https://discourse.codecombat.com/t/solved-dance-off-please-help-js/14906/18 "2022-06-12T17:05:44Z")

</div>

you can’t add a number to an object… you have to add it to x or y
