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

[SOLVED] Dance-Off Level

I need help in Dance-Off. Here is my code:

// Move in sync with your dance partner to impress Pender Spellbane.
var friend = hero.findNearest(hero.findFriends());
if (friend) {
    var ydistance = friend.pos.x - hero.pos.x;
while (true) {
 var x = hero.pos.x;
 var y = hero.pos.y;
     var yy = friend.pos.y - hero.pos.y;
     if (hero.pos.x != friend.pos.x) {
      hero.move({x: friend.pos.x, y: y});   
     }
    if (yy != 7) {
     if (yy == 8) {
      hero.move({x: x, y: y + 1});   
     } else if (yy == 6) {
      hero.move({x: x, y: y - 1});   
     }
    }
}

}```

My hero doesn't move up and down the y-axis.

Hey @BMoney could you post a screenshot of what happens when you run your code such as any erros and etc. Also thanks for properly formatting your code!

var ydistance = friend.pos.x - hero.pos.x;

Since the ydistance is combined as one try either Ydistance, yDistance, or Y/y distance. This could potientally be the problem.

Hi BMoney,

You’re making this more complicated than it needs to be! You need code that finds your partner, and then a while(true) loop that does the following:

  • Sets your hero’s x position to be the same as the partner’s x position.
  • If your hero’s y position is less than the partner’s y position, then set your y to be their y - 6
  • If your hero’s y position is more than the partner’s y position, then set your y to be their y+6.
  • Move your hero to this new x and y.

Um that’s it. Probably about 10 lines of code :grin:.

Jenny

I used a lot more and that was all I had to do Fascinating

I completed the level; thanks for the great advice!

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.