Upper Elementary
Computer Science
Introduction to Functions
Objective
Students will be able to create and use functions in a program.
Function: A sequence of code that can be called to run as a command
Vocabulary
What are functions?
Why use functions?
How can you create functions?
How can you use functions?
Here is an example of the ‘Dance’ function being called multiple times as Scout moves along the stage.
Think of a function as instructions that you use more than once.
How about your favorite cookie recipe?
You may bake the cookies in February, in June, and again in September. You don’t write out the recipe each time… you use the same recipe (function) but at different times.
Here is what we’ll make today!
Think: How are functions being used in this program?
Create a function named “Chomp.”
Define the ‘Chomp’ function.
Program the dinosaur to glide to the Chip Bag and Chomp.
Program the Chip Bag sprite.
Duplicate the Chip Bag 2 times.
Program the dinosaur to move to the new Chip Bags and Chomp.
Add a new function for the dinosaur and use it in the program.
If you have more time…
Standard | Description |
CSTA 1B: 1B-AP-10 | Create programs that include sequences, events, loops, and conditionals. |
CSTA 1B: 1B-AP-15 | Test and debug (identify and fix errors) a program or algorithm to ensure it runs as intended. |
UT CS K-5: 3.AP.1 | Create programs that include events, sequences, loops, and simple conditionals to express ideas or address a problem. |
UT CS K-5: 3.AP.3 | Test and debug a program or algorithm to ensure it accomplishes the intended task. |
UT CS K-5: 4.AP.2 | Create programs that include events, loops, and conditionals. |
UT CS K-5: 4.AP.4 | Test and debug a program or algorithm to ensure it accomplishes the intended task. |
UT CS K-5: 5.CT.1 | Develop algorithms in computer programs to solve problems, including unique and repeated sub-tasks within a larger program. |