wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Karel Conditions

Total questions: 13

Worksheet time: 7mins

Name
Class
Date
1.

How many times does Karel move with this loop?

a)

9

b)

0

c)

10

d)

1

2.

What does this error mean?

a)

missing ( ) { }

b)

missing ;

c)

missing (

d)

there is no function in the program

3.

Why do we use if/else statements in JavaScript?

a)

To repeat something for a fixed number of times

b)

To either do something if a condition is true or do something else

c)

To break out of some block of code

d)

To repeat something while a condition is true

4.

Which conditional statement should be used for this situation:


If the front is clear, Karel should move. Otherwise, Karel should turn around.

a)

if

b)

if

if

c)

if

else

d)

none of these

5.

Which conditional statement should be used for this situation:


If there is a ball, Karel should take it. Then Karel should move forward.

a)

if

b)

if

if

c)

if

else

d)

none of these

6.

Which conditional statement should be used for this situation:


If there is a ball present, Karel should take it. If the front is clear, Karel should move forward.

a)

if

b)

if

if

c)

if

else

d)

none of these

7.

Which conditional statement should be used for this situation:


If there is a ball present, Karel should take it. If there is no ball present, Karel should turn around.

a)

if

b)

if

if

c)

if

else

d)

none of these

8.

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

while (________) {

takeBall();

}

a)

noBallsPresent()

b)

ballsPresent()

c)

frontIsClear()

d)

takeBall()

9.

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

a)

ballsPresent()

b)

frontIsClear()

c)

leftIsBlocked()

d)

turnLeft()

10.

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

a)

If statement

b)

While loop

c)

For loop

d)

Nested while loop

11.

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

a)

To perform an action if a condition is true

b)

To perform an action while a condition is true

c)

To repeat an action a fixed number of times

d)

To make programs run faster

12.

What does this code do?

a)

Puts down a row of balls

b)

Puts down a column of balls

c)

Puts down balls in a line up to the wall

d)

Removes all of the balls along a path to the wall

13.

What is the best code to replace condition in this code to make Karel move to the wall in front of her?

a)

facingNorth()

b)

frontIsClear()

c)

noWallsPresent()

d)

facingWall()

e)

true