1.17.6 Checkerboard Karel

Question: 7.1.5: Go Through the Fence

Answer: function start(){

turnLeft();

while (frontIsClear()) {

move();

}

while (frontIsBlocked()) {

turnRight();

move();

turnLeft();

}

while (frontIsClear()) {

move();

}

turnRight();

while (frontIsClear()) {

move();

}

}

==================================================

Question: 6.4.5: Checkerboard Karel

Answer: function start() {

for(var i = 0; i < 3; i++){

makeaRow();

turnLeft();

move();

turnLeft();

makeaRow();

turnRight();

move();

turnRight();

}

makeaRow();

turnLeft();

move();

turnLeft();

makeaRow();

goHome();

}

function makeaRow() {

for(var i = 0; i < 3; i++){

paint(Color.black);

move();

paint(Color.red);

move();

}

paint(Color.black);

move();

paint(Color.red);

}

function goHome() {

turnLeft();

for(var i = 0; i < 7; i++){

move();

}

turnLeft();

}

==================================================

Question: 7.1.2: Racing Karel

Answer: function start(){

for(var i = 0; i < 32; i++){

setBall();

runToWall();

turnLeft();

}

}

function setBall(){

putBall();

}

function runToWall(){

while (frontIsClear()){

move();

}

}

==================================================