Drop The Flag level Java


#1

i cant pass this level…
loop {
var flag = this.findFlag();
var item = this.findNearest(this.findItems());
if (flag) {

    var pos = flag.pos;
    var fX = pos.x;
    var fY = pos.y;
    this.moveXY(fX, fY);
    this.buildXY("fire-trap", (fX + 3), fY);
    this.pickUpFlag(flag);
        }

else if (item)
{
pos = item.pos;
var itemX = pos.x;
var itemY = pos.y;
this.moveXY(itemX, itemY);
}
}


#2

Nothing jumps out as wrong with that code, what is the issue?

Also, looks like you put the code tags around part of your code, but not all of it.


#3

You might have to do

var pos = item.pos;
var x = pos.x;
var y = pos.y;
this.moveXY(x,y);


#4

I’m having trouble solving this level… The computer keeps telling me I have an error on line 9, which is var fX = pos.x;, but I don’t know what it is.

loop {
var flag = this.findFlag();
var item = this.findNearestItem;
if (flag) {
    var pos = flag.Pos;
    var fX = pos.x;
    var fY = pos.y;
    this.moveXY(fX, fY);
    this.buildXY("fire-trap", fX, fY);
    this.pickUpFlag(flag);
}
else if (item) {
        var itemPos = item.pos;
        var itemX = itemPos.x;
        var itemY = itemPos.y;
        this.moveXY(itemX, itemY);
    }

}

Thanks!


#5

You capitalized the P in flag.Pos. That would appear to be your problem.