[SOLVED] Dance-off Please help JS

// 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!

that doesn’t complete the level.

or, take out line number 4.

I know.
I have no idea what to do.

Seriously. Somebody?

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

1 Like

I like your profile picture, it’s cool.

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

Ahaha. Fan of Matrix?

1 Like

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. :sob: But yeah, I wanna watch it a lot I also want to watch the x-files.

1 Like

Makes sence. Thanks o lot!!

What stops you from it? Go and watch :slight_smile:

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.

what exactly do you need help with?

I’ve solved it already. Thanks.

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.

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
  • State what you’re having difficulties with.

Optional:

Thanks,
:lion: :lion: :lion:

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.

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

# 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)

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