WorksheetsCodeHS Javascript Unit 1 Quiz Review
Total questions: 25
Worksheet time: 2hrs 56mins
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
In the following code, what would be a good Postcondition to write?
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.
How can we improve the following program?
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
In this code, how many times is the dance function called and how many times is it defined?
Called 1 time, defined 1 time
Called 1 time, defined 3 times
Called 3 times, defined 1 time
Called 3 times, defined 3 times
What’s wrong with this code?
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
How many total times will Karel move in this program?
1
5
6
7
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
Which of the following is the correct way to define a turnRight function in Karel?
If Karel starts at Row 1 and Column 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)
Row 3, Column 1, Facing North
Row 1, Column 4, Facing North
Row 1, Column 3, Facing South
Row 1, Column 3, Facing North
Which of the following commands is a valid Karel command?
move
move;
move();
move()
Karel starts at Row 1, Column 1, facing East in a 5x5 world. What will happen after this code runs? Assume this is a SuperKarel program.
Karel ends on Row 1, Column 3
Karel ends on Row 2, Column 3
This code won’t run because of a syntax error
Karel will crash into a wall
Which of the following is not a valid condition to go in an if statement for Karel?
ballsPresent()
frontIsClear()
leftIsBlocked()
turnLeft()
What is the proper format for a single line comment in Karel?
# This is a comment
// This is a comment
/* This is a comment
<comment>This is a comment</comment>
Karel starts at Row 1 and Column 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)
Row 2, Column 2, Facing North
Row 3, Column 3, Facing East
Row 3, Column 3, Facing West
Row 4, Column 4, Facing East
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
How can we teach Karel new commands?
For loop
While Loop
Define a Function
The main function
Karel starts at Row 1, Column 1, facing East in a 5x5 world. What will happen after this code runs?
Karel will end on Row 1, Column 2
Karel will end on Row 1, Column 7
This code won’t run because of a syntax error
Karel will crash into a wall
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?
0
1
2
6
What is wrong with this for loop?
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
In the following code below from the Cleanup Karel example, what is the purpose of If Statement #2?
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
What condition should be used in this while loop to get Karel to pick up all the tennis balls on the current location?
noBallsPresent()
ballsPresent()
frontIsClear()
takeBall()
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 others
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 others
What does the mystery function do?
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
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
