1.13.5 Lay Row Of Tennis Balls
Question: 1.9.5: Take ‘em All
Answer: function start(){
// Write your code here
move();
for(var i = 0; i < 100; i++){
takeBall();
}
move();
}
Question: 1.9.6: Dizzy Karel
Answer: function start(){
for(var i = 0; i < 32; i++){
turnLeft();
}
}
Question: 1.9.7: For Loop Square
Answer: function start(){
for(var i = 0; i < 4; i++){
move();
turnLeft();
putBall();
}
}
Question: 1.9.8: Lots of Hurdles
Answer: function start(){
for(var i = 0; i < 5; i++){
move();
move();
turnLeft();
move();
turnRight();
move();
turnRight();
jumpHurdle();
turnLeft();
}
}
function jumpHurdle(){
move();
}
Question: 1.10.5: Is There a Ball?
Answer: function start(){
safePutBall();
move();
}
function safePutBall(){
if(noBallsPresent()){
putBall();
}
}
Question: 1.11.5: Right Side Up
Answer: function start(){
if (facingSouth()) {
turnLeft();
}
if (facingWest()) {
turnAround();
}
}
Question: 1.12.4: Follow The Yellow Ball Road
Answer: function start() {
while(ballsPresent()){
move();
}
}
Question: 1.12.5: Lay Row of Tennis Balls
Answer: function start(){
while(frontIsClear()){
putBall();
move();
}
putBall();
}
Question: 1.12.6: Big Tower
Answer: function start(){
north();
clear();
putBall();
}
function clear(){
while (frontIsClear()) {
putBall();
move();
}
}
function north(){
while (notFacingNorth()) {
turnLeft();
}
}
Question: 1.13.4: Random Hurdles
Answer: function start(){
for (var i = 0; i < 13; i++) {
if (frontIsClear()) {
move();
} else {
jumpHurdle();
}
}
}
function jumpHurdle(){
turnLeft();
move();
turnRight();
move();
turnRight();
move();
turnLeft();
}