这是我尝试过的代码。
function main() {
while (frontIsClear()) {
//this tells karel to go and put beepers
putBeeper();
move();
}
if (frontIsBlocked()) {
//this tells karel to change the direction if there's a wall
if (facingEast()) {
turnLeft();
putBeeper();
if (frontIsClear()) {
//and this brings karel to the upper street
move();
turnLeft();
} else {
turnRight();
}
}
if (facingWest()) {
turnRight();
putBeeper();
if (frontIsClear()) {
move();
turnRight();
} else {
turnRight();
}
}
}
}
当我运行代码时,它给了我一个错误。它说 ReferenceError: virtualDirection is not defined。请帮忙。谢谢。