Which of the following commands is a valid Karel command?

move

move;

move();

move()
Question: 2
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();
}
JavaScript

Street 2, Avenue 2, Facing North

Street 3, Avenue 3, Facing East

Street 3, Avenue 3, Facing West

Street 4, Avenue 4, Facing East

Question: 3
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

Question: 4
How can we teach Karel new commands?

For loop

While loop

Define a new function

The start function

Question: 5
Say Karel is on a location with one tennis ball. After the following code runs, how many tennis balls will there be at that location?

for (var i = 0; i < 3; i++) {
if (ballsPresent()) {
takeBall();
} else {
putBall();
putBall();
}
}
JavaScript

0

1

2

6

Question: 6
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.

Top down design is a way that you can create designs on a computer to put on a web page

Top down design is a way of designing your programs starting with the individual commands first

Top down design is a way to use loops and if statements to decompose the problem

Question: 7
Which of the following is the correct way to define a turnRight function in Karel?

function turnRight() {
turnLeft();
turnLeft();
turnLeft();
}

function turnRight() {
turnRight();
turnRight();
turnRight();
}

function turnRight {
turnLeft();
turnLeft();
turnLeft();
}

turnRight function() {
turnLeft();
turnLeft();
turnLeft();
}
Question: 8
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

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

ballsPresent()

frontIsClear()

leftIsBlocked()

turnLeft()
Question: 10
What is the proper format for a single line comment in Karel?

This is a comment

// This is a comment

/* This is a comment

This is a comment

Question: 11
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();
}
JavaScript

Called 1 time, defined 1 time

Called 1 time, defined 3 times

Called 3 times, defined 1 time

Called 3 times, defined 3 times

Question: 12
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();
}
JavaScript

noBallsPresent()

ballsPresent()

frontIsClear()

takeBall()
Question: 13
What’s wrong with this code?

function start() {
move();
go();
go();
}

function go() {
move();
move();
}

function go() {
move();
move();
}
JavaScript

The go function is called twice

The go function has a syntax error

The go function has been defined twice

go is not a command that Karel understands

Question: 14
What does the mystery function do?

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

Karel moves until it is on a ball

Karel moves once if there is no ball present

Karel moves until it puts down a ball

Karel checks if there is no ball on the current spot and then moves once

Question: 15
How many total times will Karel move in this program?

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

1

5

6

7

Question: 16
How can we improve the following program?

function start() {
move();
move();
move();
move();
move();
move();
move();
move();
move();
}
JavaScript

Break down this program into more functions

Use a for loop to repeat the move command

Use a while loop to repeat the move command

Fix the indentation of this program

Question: 17
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

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

// This program has Karel walk down the
// row and clean up all of the tennis balls
// on the way.
function start() {
while (frontIsClear()) {
// If statement #1
if (ballsPresent()) {
takeBall();
}
move();
}
// If statement #2
if (ballsPresent()) {
takeBall();
}
}
JavaScript

To move the last time

To pick up the ball that is in the last spot

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

To take the ball from all of the positions that have a ball on them

Question: 19
Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs? Assume this is a SuperKarel program.

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

Karel ends on street 1, avenue 3

Karel ends on street 2, avenue 3

This code won’t run because of a syntax error

Karel will crash into a wall

Question: 20
Why is the following command an invalid Karel command?

turnleft();

It should end in a colon rather than a semicolon

The l should be a capital L

It should start with a capital T

This command is correct

Question: 21
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();
JavaScript

Street 3, Avenue 1, Facing North

Street 1, Avenue 4, Facing North

Street 1, Avenue 3, Facing South

Street 1, Avenue 3, Facing North

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

To do something if a condition is true

To do something while a condition is true

To repeat something a fixed number of times

To make programs run faster

Question: 23
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();
JavaScript

Karel will end on Street 1, Avenue 2

Karel will end on Street 1, Avenue 7

This code won’t run because of a syntax error

Karel will crash into a wall

Question: 24
What is wrong with this for loop?

for (var i = 0, i < 10, i + 1) {
move();
}
JavaScript
I. The for loop uses commas instead of semicolons

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

I

II

I and II

The for loop is correct

Question: 25
In the following code, what would be a good Postcondition to write?

/* Precondition: Karel is on a spot with a tennis ball facing East
* Postcondition: ...
*/
function getOnTop() {
turnLeft();
move();
turnRight();
}
JavaScript

Karel is on a spot with a tennis ball facing north

Karel ends one spot above a tennis ball facing East.

Karel is on the same position but on top of a ball.

Karel is facing East.

answer 1-25

1. move

2. Street 3, Avenue 3, Facing East
3. All of the above
4. Define a new function
5. 6
6. 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.
7. function turnRight() {
turnLeft();
turnLeft();
turnLeft();
}
8. All of the above
9. turnLeft()
10. // This is a comment
11. Called 1 time, defined 1 time
12. ballsPresent()
13. The go function has been defined twice
14. Karel moves until it is on a ball
15. 7
16. Use a for loop to repeat the move command
17. For loop
18. To pick up the ball that is in the last spot, if there is one
19. Karel ends on street 2, avenue 3
20. It should start with a capital T
21. Street 3, Avenue 1, Facing North
22. To repeat something a fixed number of times
23. Karel will crash into a wall
24. I
25. Karel ends one spot above a tennis ball facing East.

1. The valid Karel command is "move".

2. After calling the stairStep function twice, Karel will be at Street 3, Avenue 3, facing West.

3. Programmers indent their code to help show the structure of the code, make it easier for other people to understand, and as a key part of good programming style.

4. We can teach Karel new commands by defining a new function.

5. After the code runs, there will be 1 tennis ball at the location.

6. 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.

7. The correct way to define a turnRight function in Karel is:

```
function turnRight() {
turnLeft();
turnLeft();
turnLeft();
}
```

8. We use functions in Karel programs to break down our program into smaller parts, avoid repeating code, and make our program more readable.

9. The valid condition to go in an if statement for Karel includes ballsPresent(), frontIsClear(), and leftIsBlocked(). However, turnLeft() is not a valid condition for an if statement in Karel.

10. The proper format for a single line comment in Karel is "// This is a comment".

11. The dance function is called 3 times and defined 1 time in the given code.

12. The condition that should be used in the while loop to get Karel to pick up all the tennis balls on the current location is "ballsPresent()".

13. The go function has been defined twice in the given code, which is wrong.

14. The mystery function makes Karel move until there is no ball present on the current spot.

15. Karel will move a total of 7 times in the given program.

16. To improve the given program, we can break it down into more functions, use a for loop to repeat the move command, or use a while loop to repeat the move command.

17. To have Karel put down 300 tennis balls, we would use a for loop.

18. If Statement #2 is used to pick up the ball that is in the last spot, if there is one.

19. After the code runs, Karel will end on Street 1, Avenue 3.

20. The following command is an invalid Karel command because it should be "turnLeft()" instead of "turnleft()".

21. After running the given code, Karel will be at Street 1, Avenue 3, facing North.

22. The purpose of using a for loop in code is to repeat something a fixed number of times.

23. After the code runs, Karel will crash into a wall.

24. The for loop is wrong because it uses commas instead of semicolons. The correct version should be:

```
for (var i = 0; i < 10; i++) {
move();
}
```

25. A good postcondition for the given code could be "Karel is on the same position but on top of a ball.".

1. The valid Karel command is "move".

2. After calling the stairStep function twice, Karel will be at Street 3, Avenue 3, facing West.
3. The reason programmers indent their code is to help show the structure of the code, make it easier for other people to understand, and it's a key part of good programming style.
4. We can teach Karel new commands by defining a new function.
5. After the code runs, there will be 2 tennis balls at the location where Karel started.
6. Top down design is a way of designing a program by starting with the biggest problem and breaking it down into smaller and smaller pieces that are easier to solve.
7. The correct way to define a turnRight function in Karel is `function turnRight() { turnLeft(); turnLeft(); turnLeft(); }`.
8. Functions are used in Karel programs to break down the program into smaller parts, avoid repeating code, and make the program more readable.
9. The invalid condition to go in an if statement for Karel is "turnLeft()".
10. The proper format for a single line comment in Karel is "// This is a comment".
11. The dance function is called 3 times and defined 1 time in the code.
12. The condition to go in the while loop to get Karel to pick up all the tennis balls on the current location is "ballsPresent()".
13. The code has a syntax error because the function "go" has been defined twice.
14. The mystery function makes Karel move until there are no tennis balls present on the current spot.
15. Karel will move a total of 7 times in the program.
16. The program can be improved by using a for loop to repeat the move command.
17. To have Karel put down 300 tennis balls, we would use a for loop.
18. If Statement #2 is used to pick up the ball that is in the last spot, if there is one.
19. After the code runs, Karel will end on Street 1, Avenue 3.
20. The command "turnleft();" is invalid because it should start with a capital T.
21. After running the code, Karel will be at Street 1, Avenue 3, facing North.
22. The purpose of using a for loop is to repeat something a fixed number of times.
23. After running the code, Karel will crash into a wall.
24. The for loop is incorrect because it uses commas instead of semicolons and it should say "i++" instead of "i + 1".
25. A good Postcondition for the function getOnTop would be "Karel is on the same position but on top of a ball."