Help with perimeter defense

this level is easy and straightforward, I follow the instructions but for some reason it is ignoring the south border code
here is the code :

// First move along the north border (y=60) from x=40 to x=80 with the step 20.
for (var x = 40; x <= 80; x += 20) {
    // Move at each point and say anything.
    hero.moveXY(x, 60);
    hero.say("Here");
}
// Next move along the east border (x=80) from y=40 to y=20 with the negative step -20.
for (var y = 40; y >= 20; y -= 20) {
    hero.moveXY(80, y);
    hero.say("Here");
}
// Continue for the two remaining borders.
// Next the south border (y=20) from x=60 to x=20 with the negative step -20.
for (var x = 60; x <= 20; x -= 20) {
    hero.moveXY(x, 20);
    hero.say("here");
}
// Next the west border (x=20) from y=40 to y=60 with the step 20.
for (var y = 40; y <= 60; y += 20) {
    hero.moveXY(20, y);
    hero.say("Here");
}
// Don't forget hide inside the village.
hero.moveXY(50, 40);

this is the hero’s trajectory

Check condition for south for()

1 Like

I checked many times, I wrote it like the north sample code, but it won’t work

ok lets see that you have

for ( var x = 60; (while following expression is true) x less or equal 20 ; x -= 20 )

1 Like

should I use more or equal instead ?

PS: sorry for not replying, been very busy with other stuff

For loop will execute only if condition is true

for (var x = 60; x <= 20; x -= 20) {
    hero.moveXY(x, 20);
    hero.say("here");
}

var x = 60 sets a variable before the loop starts
x <= 20 defines the condition for the loop to run
x -= 20 is executed each time after the loop has been executed.
60 - 20
40 - 20
20 - 20

x(60) >= ( more or equal ) 20
true or false?

1 Like

ok, I understand, thank you