T/F: In an if/else statement, it is possible for both the if block and the else block to run.
Answer: False
Why: It is a choice: either the if block runs (if the condition is true) or the else block runs (if the condition is false), but never both.
T/F: A while loop will continue to run as long as its condition remains true.
Answer: True
Why: This is the definition of a while loop. It checks the condition, runs the code, and repeats, stopping only when the condition becomes false.
T/F: Debugging is the process of writing new functions to add features.
Answer: False
Why: Debugging is the process of finding and fixing errors (bugs) in your code.
T/F: Proper code indentation is technically required for a Karel program to run.
Answer: False
Why: While not required for the computer to run it, it is essential for human readability and is a critical part of good programming style.
T/F: A function call (like move();) is a type of control structure.
Answer: False
Why: Control structures (like if, for, while) change the flow of the program. A function call is just a command.
What is the primary purpose of Karel the Dog in programming education?
A) To teach object-oriented design
B) To learn the basics of logic and problem-solving
C) To build web pages
D) To learn advanced JavaScript syntax
Answer: B
Why: Karel provides a simple, visual environment to learn fundamental concepts like commands, logic, and decomposition before adding complex syntax.
If Karel is at 3rd Street and 5th Avenue facing East, what will its location be after one move() command? A) 3rd Street and 6th Avenue
B) 4th Street and 5th Avenue
C) 3rd Street and 4th Avenue
D) 2nd Street and 5th Avenue
Answer: A
Why: Facing East means moving to higher avenues. Streets (North/South) remain unchanged.
Which command does Karel use to pick up a tennis ball?
A) pickBall()
B) getBall()
C) takeBall()
D) removeBall()
Answer: C
Why: The specific command in the CodeHS Karel library is takeBall().
How do you correctly define a turnRight() function for the basic Karel?
A) function turnRight() { turnLeft(); turnLeft(); }
B) function turnRight() { turnLeft(); turnLeft(); turnLeft(); }
C) function turnRight() { move(); turnLeft(); }
D) function turnRight() { SuperKarel.turnRight(); }
Answer: B
Why: Turning left three times (90 + 90 + 90 = 270 degrees) results in a right turn.
What is the primary benefit of using functions in your code?
A) It makes the code run faster.
B) It allows you to avoid writing the same code repeatedly and makes code more readable.
C) It is the only way to use loops.
D) It makes the code more colorful.
Answer: B
Why: Functions promote reusable code (D.R.Y. - Don't Repeat Yourself) and help with decomposition.
How do you write a single-line comment in Karel (and JavaScript)?
A) ``
B) /* This is a comment */
C) `// This is a comment`
D) `# This is a comment`
Answer: C
Why: // is for single-line comments. /* ... */ is for multi-line comments.
"Starting with the main goal and breaking it into high-level steps, then breaking those steps into smaller steps" describes:
A) Bottom-up design
B) Top-down design
C) Loop design
D) Debugging
Answer: B
Why: This is the definition of top-down design, starting from the "top" goal.
The process of breaking a large, complex problem into smaller, more manageable pieces is called:
A) Decomposition
B) Debugging
C) Commenting
D) Looping
Answer: A
Why: Decomposition is the core idea of top-down design, breaking a problem "down" into simpler parts.
Which function in a Karel program is automatically run first?
A) start()
B) karel()
C) The first function defined in the file
D) main()
Answer: D
Why: The main() function is the designated entry point for the entire program.
What is the correct syntax for calling (using) a function named buildHouse?
A) function buildHouse();
B) buildHouse;
C) buildHouse()
D) buildHouse();
Answer: D
Why: You must use the function name followed by parentheses () and a semicolon ;.
What is the purpose of a "precondition" comment?
A) To describe what the function does in general.
B) To state what must be true before the function is called for it to work.
C) To state what will be true after the function is finished.
D) To explain why the function is needed.
Answer: B
Why: A precondition is a condition that must be met pre- (before) running the function for it to work correctly.
Which command is available in SuperKarel but NOT in the basic Karel?
A) move()
B) turnAround()
C) takeBall()
D) turnLeft()
Answer: B
Why: SuperKarel adds turnRight() and turnAround() as built-in commands.
Which control structure is best for making Karel move forward exactly 5 times?
A) if statement
B) while loop
C) for loop
D) if/else statement
Answer: C
Why: A for loop is used to repeat code a fixed (known) number of times.
What is the correct syntax for a for loop that runs 10 times?
A) for (var i = 0; i < 10; i++) { ... }
B) for (i = 1 to 10) { ... }
C) loop (10) { ... }
D) while (i < 10) { ... }
Answer: A
Why: This is the standard "counter" loop: initialize i to 0, loop as long as i is less than 10, and increment i each time.
Which command does Karel use to put down a tennis ball?
A) dropBall()
B) putBall()
C) leaveBall()
D) placeBall()
Answer: B
Why: The command is putBall().
What does the condition facingNorth() check?
A) If there is a wall to the North.
B) If Karel is currently facing the North direction.
C) If Karel is on the northernmost street.
D) If there is a ball to the North.
Answer: B
Why: It checks Karel's current orientation (direction).
If you want Karel to takeBall() only if one is present, what code would you write?
A) while (ballsPresent()) { takeBall(); }
B) if (ballsPresent()) { takeBall(); }
C) if (takeBall()) { ballsPresent(); }
D) for (var i = 0; i < 1; i++) { takeBall(); }
Answer: B
Why: An if statement checks a condition once and executes the code if it's true. A while loop (A) would get stuck if there were multiple balls.
Which of the following is NOT a valid Karel condition? A) frontIsClear()
B) ballsPresent()
C) facingEast()
D) wallIsPresent()
Answer: D
Why: The valid conditions are frontIsClear() or frontIsBlocked().
An if/else statement is used to...
A) Repeat a block of code multiple times.
B) Choose between two different actions based on a condition.
C) Define a new function.
D) Stop the program if an error occurs.
Answer: B
Why: It provides two paths: one for true (the if block) and one for false (the else block).
If ballsPresent() is false, which part of this code will run?
if (ballsPresent()) {
takeBall();
} else {
putBall();
}
A) takeBall();
B) putBall();
C) Both will run.
D) Neither will run.
Answer: B
Why: Since the condition (ballsPresent()) is false, the code inside the else block is executed.