Which of the following commands is a valid Karel command?
move();
What makes the following command an invalid Karel command?
turnleft();
The l should be a capital L
Which of the following is the correct way to define a turnRight function in Karel?
function turnRight() {
turnLeft();
turnLeft();
turnLeft();
}
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
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
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
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
What's wrong with this code?
function start() {
move();
go();
go();
}
function go() {
move();
move();
}
function go() {
move();
move();
}
The go function has been defined twice
How many total times will Karel move in this program?
function start() {
move();
for (var i = 0; i < 5; i++) {