Real World Programming - Control Structures
What do we use control structures for in JavaScript?
Control the flow of the program; how the commands execute.
Why should a programmer indent their code? A. Helps show the structure of the code B. Easier for other people to understand C. Indenting is a key part of good programming style D. All of the above
D
You need to write a program that has Karel move 6 times and then put a ball. Which control structure do you need to use?
For loop
Which of the below are examples of control structures? (I) if (II) if/else (III) while (IV) for
I, II, III, IV
You need to write a program that has Karel move if the front is clear, but if it isn't clear, Karel will do nothing. Which control structure do you need to use?
If Statement
You need to write a program that has Karel put down a tennis ball if the world has dimensions of 1x1. Which control structure do you need to use?
If Statement
You need to write a program where Karel will take a ball if there is a ball present, otherwise Karel should put down a ball. Which control structure do you need to use?
If/Else statement
What is a parameter?
Input into a function
You need to write a program that has Karel take all the tennis balls where Karel is standing if there are any there. Karel should end up with no tennis balls on that spot. Which control structure do you need to use?
While loop
Which of the following is the correct way to have Ultra Karel paint a red square using the paint function?
paint(Color.red);