[AP CSP] [Introduction to Programming (with Karel)] [04] Functions in Karel
[AP CSP] [Introduction to Programming (with Karel)] [04] Functions in Karel
What is a function?
A function is a way to teach Karel a new word
Why use functions?
Functions allow us to
spinTwice() Good!
spinTwice() Good!
buildTower() Good!
spinTwice() Good!
buildTower() Good!
move5Times() Good!
spinTwice() Good!
buildTower() Good!
move5Times() Good!
buildTower() Good!
spinTwice() Good!
buildTower() Good!
move5Times() Good!
buildTower() Good!
take4Balls() Good!
Defining a Function vs. Calling a Function
Defining a function:
Teaching Karel the new word
Calling a function:
Actually getting Karel to do the command
Defining a Function vs. Calling a Function
Defining a function:
Writing out the instructions for this new action
Calling a function:
Actually causing the action to happen
Defining turnAround()
function turnAround() {
turnLeft();
turnLeft();
move();
move();
turnLeft();
Calling turnAround()
turnAround();
move();
move();
turnLeft();
turnAround();
This tells Karel to do the action
again!
Defining turnAround()
function turnAround() {
turnLeft();
turnLeft();