I need help on thunderhooves and my code is not working and I have no reason as to why it is not

// Get to the oasis,
// fencing off paths with yaks on them as you go.
loop {
    var yak = this.findNearestEnemy();
    if (yak) {
        // A yak is above you if it's y is greater than your y.
        // If the yak is above you, build a fence 10m below it.
        if (this.distanceTo(yak) > y) {
            this.buildXY("fence", x, y + 4);
        }
        // If the yak is below you, build a fence 10m above it.
        if (this.distanceTo(yak) < y) {
            this.buildXY("fence", x, y - 4);
        }
    } else {
        // Move right 10m towards the oasis.
        var x = this.pos.x + 10;
        var y = this.pos.y;
        this.moveXY(x, y);
    }
}

You are using x & y, but where do you set them??
The directions say “build a fence 10m below/above it.” but I see “±4” not ±10.
The directions suggest you check where the yak is not how far away.

if (this.distanceTo(yak) < y) {
            this.buildXY("fence", x, y - 4);

If you are unsure how to set x & y look at the else clause…
(Should you build the fence above/below you (this) or the yak (yak)?)