Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Dance-off Please help JS

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

#2

that doesn’t complete the level.

#3

or, take out line number 4.

#4

I know.
I have no idea what to do.

#5

Seriously. Somebody?

#6

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

#7

I like your profile picture, it’s cool.

#8

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

Ahaha. Fan of Matrix?

#9

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.

#10

Makes sence. Thanks o lot!!

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

#11

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.

#12

what exactly do you need help with?

#13

I’ve solved it already. Thanks.

#14

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.

#15

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: