What is the difference between an IF statement and a WHILE loop?
IF statement only runs once, WHILE loop can run multiple times depending on a condition.
When do you use a FOR loop?
When you need to repeat something a fixed number of times.
What function do you never call?
What should you indent in an IF statement?
Everything between the curly brackets { }
How do you write a single line comment?
// You use two forward slashes
move(); // You can also comment on the same line as code
What can be used to teach Karel to turn right?
A. Functions B. Variables C. Loops D. Dog treats
A. Functions
Using the following loop, how many times will Karel move?
for (var i = 0; i < 8; i++) {
move();
}
8 times
Karel needs to follow a line of balls but you don't know how many. Which type of loop should you use?
While loop
What are the two things you must do with a function when coding?
1. Define the function
2. Call the function
What are the possible values of a condition like frontIsBlocked() or noBallsPresent()?
True or false
How do you write a multi-line comment?
/* Use a forward slash and star to begin
And a star and forward slash to end */
What is syntax?
The rules for how you must type code for a certain programming language.
What are the rules for naming a function?
- Name should start with a letter
- No spaces
- Name should describe what the function does
What is the proper syntax in Karel for a FOR loop?
for (var i = 0; i < #; i++) {
\* Type loop body here *\
}
Karel needs to clean up a bunch of balls in different places. The world is always going to be 5 spaces wide. What loop(s) should Karel use? What should the loop(s) do?
While loop to pick up each pile of balls.
For loop to move across the world and call a cleanup function.
What is the proper syntax in Karel for defining a function called eatHamSandwich?
function eatHamSandwich() {
/* Type function body here */
}
Write a "real life" example of a conditional statement.
Mr. Porter's example: "If students study hard, then they will do well on the quiz and grow 1" taller."
Insert your example here!
What is top-down design?
Start with a big problem and break it into smaller parts.
What is pseudocode?
Short phrases that explain what you want your code to do. You can write this before you write the real code.
How many times should the start function be defined in a program?
How many times should the start function be called in the program?
Defined: 1 time
Called: 0 times
What does i++ mean?
Increase i by 1
Give an example of an infinite (never ending) FOR loop.
for(var i=0; i>-1; i++){
putBall();
}
What is the proper syntax in Karel for calling a function named devourBagel?
devourBagel();
What is the proper syntax in Karel for an if...then statement?
if ( condition() ) {
/* run this code if true */
}
What are pre-conditions and post-conditions when it comes to functions?
Mr. Porter will say the answer out loud.
What is camel case?
A good way to write function names:
makePancakes finishBellwork stayOnTask askQuestions workTogether beKindToEachOther
Karel is facing North. After the following code, which direction is Karel facing?
turnLeft();
turnLeft();
move();
South
What are the three arguments that go into a FOR loop?
1. Define the counter variable (var i = 0;)
2. Specify the end condition (i < 10;)
3. Specify how the loop iterates (i++)
Give an example of an infinite (never ending) WHILE loop.
while(noBallsPresent()){
turnLeft();
}
What are three reasons to use functions?
1. Break down the program into smaller parts
2. Avoid repeated code (save time and lines of code)
3. Make the program more readable
What is the proper syntax in Karel for an if...then...else statement?
if ( condition() ) {
/* run this code if true */
} else {
/* run this code if false */
}
Why should you use comments?
To give an explanation/reminder of what your code does. A good approach is to write what you were thinking when you wrote the code.
What is nesting?
Nesting is writing a loop inside a loop or a conditional inside a conditional or calling a function inside another function.
Define a function with correct syntax to teach Karel to turn around and move forward 1 space. Name the function using camel case.
turnLeft();
turnLeft();
move();
}