Answer:
/*This will make karel take all the balls in a world and
*end up back in its original location and it will face
*south when it is complete.
*/
function start() {
ballsTaken();
while(leftIsClear()){
endUpFacingEast();
ballsTaken();
if(rightIsClear()){
endUpFacingWest();
ballsTaken();
}else{
turnAround();
}
}
}
function ballsTaken(){
if(ballsPresent()){
takeBall();
}
while(frontIsClear()){
move();
if(ballsPresent()){
takeBall();
}
}
}
function endUpFacingEast(){
turnLeft();
move();
turnLeft();
}
function endUpFacingWest(){
turnRight();
move();
turnRight();
}
Explanation:
try this