[Solved] Fence Builder - Bottom left corner not being built


#1

For some reason, the bottom left corner in Fence Builder is not being built. I can’t find any fault within my code since I copied and pasted from the example code and changed the values around, so it should’ve worked perfectly.

This is what is happening:

and this is my code:

// Build a fence around the farm.
// Take coordinates of the opposite corners.
var customer = hero.findNearest(hero.findFriends());
var x1 = customer.leftBottom.x;
var y1 = customer.leftBottom.y;
var x2 = customer.rightTop.x;
var y2 = customer.rightTop.y;
var step = 4;
// Let's build the bottom side.
for (var x = x1 + step; x <= x2; x += step) {
    hero.buildXY("fence", x, y1);
}
// Then the right side.
for (var y = y1 + step; y <= y2; y += step) {
    hero.buildXY("fence", x2, y);
}
// Build the top side.
for (var x = x1 + step; x <= x2; x += step) {
    hero.buildXY("fence", x, y2);
}
// // Build the left side.
for (var y = y1 + step; y <= y2; y += step) {
    hero.buildXY("fence", x1, y);
}

What’s the issue here?


#2

There are a couple of errors in your code. Remember that each variable, x1, y1, x2, and y2, all stand for a corner. So to help visualize, you could replace the variable with leftBottom and etc. Some of the arrows in the if else statements are pointed the wrong direction, some are >=. Also, you reference the wrong corners sometimes, for example, maybe y1 instead x1 (just an example, may not be true). It’s not always +=. Some if statements will require -=. The level seems intimidating at first, but if you realize that + means moving up or right and - means moving left or down, the level becomes a piece of :cake:. (It’s hard to help with this level without giving away too much.)


#3

Thanks! I figured it out by changing a small detail.