Dangerous tracks help (js)[SOLVED]

For some reason, the computer completely skips eastLine and southLine. Can you explain why?
Here’s my code:

// Protect the village with fire traps.
// Mine all passages in four directions.
// You have 80 seconds before the ogres attack.

// Build traps on the line y=114 from x=40 to x=112 with step=24.
function buildNorthLine() {
    for (var x = 40; x <= 112; x += 24) {
        hero.buildXY("fire-trap", x, 114);
    }
}

// Build traps on the line x=140 from y=110 to y=38 with step=18.
function buildEastLine() {
    // Complete this function:
    for (var y = 110; y <= 38; y -= 18) {
        hero.buildXY("fire-trap", 140, y);
    }
}

// Build traps on the line y=22 from x=132 to x=32 with step=20.
function buildSouthLine() {
    // Complete this function:
    for (var x = 132; x <= 32; x -= 20) {
        hero.buildXY("fire-trap", x, 22);
    }
}

// Build traps on the line x=20 from y=28 to y=108 with step=16.
function buildWestLine() {
    // Complete this function:
    for (var y = 28; y <= 108; y += 16) {
        hero.buildXY("fire-trap", 20, y);
    }
}

buildNorthLine();
buildEastLine();
buildSouthLine();
buildWestLine();
hero.moveXY(40, 94);

Hi foxfire,

Have a think about the for loop. This line

for (var x = 40; x <= 112; x += 24) {

can be said as “start with x at 40 and complete the action. Then add 24 to x. If x is less than or equal to 112 then repeat”.

Try saying the equivalent line for buildEastLine.

for (var y = 110; y <= 38; y -= 18) {

What goes wrong?

Jenny

1 Like

@jka2706 ohhh I see now!
thank you for the help, I tried it and it worked!
I also noticed that you helped me with a lot of problems I had here, so extra-special thanks :star_struck:

1 Like

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