Commands
Functions
Conditions
Variety
Hard Times
100

How can we improve the following program?

function start() {    

move();    

move();    

move();    

move();    

move();    

move();    

move();    

move();    

move();
}

Use a for loop to repeat the move command

100

What does the mystery function do?

function mystery() {    while (noBallsPresent()) {        move();    

      }
}

Karel moves until it is on a ball

100

Define Condition

What are statements that are created by the programmer which evaluates actions in the program and evaluates if it's true or false.

100

Why does a programmer indent their code?

Helps show the structure of the code.

Easier for other people to understand.

A key part of good programming style!

All of the above

All of the above

100

What is wrong with this for loop?

for (var i = 0, i < 10, i + 1) {    

     move();
}

A. The for loop uses commas instead of semicolons

B. It should say i++ instead of i + 1

A and B

200

Which of the following commands is a valid Karel command? 

move

move;

move();

move();

200

In the following code below from the Cleanup Karel example, what is the purpose of If Statement #2? 

function start() {  

  while (frontIsClear()) {  

      // If statement #1        

if (ballsPresent()) {            

takeBall();        

}        

move();   

 }    

// If statement #2   

if (ballsPresent()) {       

 takeBall();   

     }
}

To pick up the ball that is in the last spot, if there is one

200

Which of the following is not a valid condition to go in an if statement for Karel? 

ballsPresent()

frontIsClear()

leftIsBlock()

turnLeft()

turnLeft()

200


Say you want to write a program to have Karel put down 300 tennis balls. Which control structure would you use?

If statement

While loop

For loop

Nested while loop

For loop

200

In this code, how many times is the dance function called and how many times is it defined?

function start() {    

     move();    

     dance();    

     move();    

     move();    

     turnLeft();    

     dance();    

     dance();
}

function dance() {    

     turnLeft();    

     move();    

     turnLeft();    

     turnLeft();    

     move();    

     turnLeft();
}

Called 3 times, defined 1 time

300

What makes the following command an invalid Karel command? 

turnleft();

The l should be a capital L

300

Define the correct function to have Karel turnRight

Function turnRight () {

     turnLeft();

     turnLeft();

     turnLeft();

}


300

What condition should be used in this while loop to get Karel to pick up all the tennis balls on the current location?

while (________) {    

     takeBall();
}

ballsPresent()

300

What is the purpose of using a for loop in code?

To repeat something a fixed number of times

300

Super Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs?

move();
move();
turnRight();
move();

Karel will crash into a wall

400

Define Command

What is a directive to a computer program to perform a specific task 

400


How many total times will Karel move in this program?

function start() {   
     move();    
     for (var i = 0; i < 5; i++) {       
          move();       
          putBall();   
     }
}




6

400

Karel starts at Street 1 and Avenue 1, facing East. After calling the stairStep function twice, where will Karel be and what direction will Karel be facing? (assume this is a SuperKarel program and the world is 10x10 in size)

function stairStep() {    

     move();    

     turnLeft();    

     move();    

     turnRight();
}

Street 3, Avenue 3, Facing East

400

Why do we use functions in Karel programs? 

Break down our program into smaller parts

Avoid repeating code

Make our program more readable

All of the above

All of the above

400

n the following code, what would be a good Postcondition to write? 

function getOnTop() {    

     turnLeft();   

     move();    

     turnRight();
}

Karel ends one spot above a tennis ball facing East.

500

How can we teach Karel new commands?

Define a new function

500

Define Function

What is a block of organized, reusable code that is used to perform a single, related action 

500

If Karel starts at Street 1 and Avenue 1, facing East, where will Karel be, and what direction will Karel be facing after running the following code? (Assume the world is 10x10 in size)

move();
turnLeft();
putBall();
turnLeft();
turnLeft();
turnLeft();
move();
turnLeft();

Street 1, Avenue 3, Facing North

500

What is top down design?

Top down design is a way of designing your program by starting with the biggest problem and breaking it down into smaller and smaller pieces that are easier to solve.

500

Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs?

move();
putball();
move();
move();
move();
move();
move();

This code won't run because of a syntax error