Font size
WorksheetsCodeHS Intro to Programming - Karel Review
Total questions: 10
Worksheet time: 5mins
Which of the following commands is a valid Karel command?
turnLeft
turnLeft;
turnLeft();
turnLeft()
What makes this command invalid (incorrect)?
Move();
This command is correct.
It has a capital M.
It has ()
It should be a colon : not a semi colon ;
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();
}
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 these!
How many total times will Karel move in this program?
function start() { move(); for (var i = 0; i < 5; i++) { move(); putBall(); } }
1
5
6
7
What is wrong with this for loop?
for (var i = 0; i < 10; i + 1) { move(); }
The for loop uses commas instead of semicolons
It should say i++ instead of i + 1
Nothing is wrong with this loop
The "var" should not be there.
How can we teach Karel new commands?
For loop
While loop
Define a new function
The start function
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
How can we improve the following program?
function start() { move(); move(); move(); move(); move(); move(); move(); move(); move(); }
Break down this program into more functions
Use a for loop to repeat the move command
What is the purpose of using a for loop in code?
To do something if a condition is true
To repeat something a fixed number of times
To make programs run faster
