1 of 18

Upper Elementary

Computer Science

Introduction to Functions

2 of 18

Objective

Students will be able to create and use functions in a program.

3 of 18

Function: A sequence of code that can be called to run as a command

Vocabulary

4 of 18

What are functions?

  • A function is like a recipe that tells the computer what to do step by step.
  • Functions help us avoid repeating the same code and make our projects easier to understand.

5 of 18

Why use functions?

  • Functions make our code organized and easier to read.
  • They allow us to reuse code without rewriting it.
  • Examples of functions in real life: baking a cake (recipe), building a LEGO set (instructions)

6 of 18

How can you create functions?

7 of 18

How can you use functions?

Here is an example of the ‘Dance’ function being called multiple times as Scout moves along the stage.

8 of 18

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.

9 of 18

Here is what we’ll make today!

Think: How are functions being used in this program?

10 of 18

Create a function named “Chomp.”

11 of 18

Define the ‘Chomp’ function.

12 of 18

Program the dinosaur to glide to the Chip Bag and Chomp.

13 of 18

Program the Chip Bag sprite.

14 of 18

Duplicate the Chip Bag 2 times.

15 of 18

Program the dinosaur to move to the new Chip Bags and Chomp.

16 of 18

Add a new function for the dinosaur and use it in the program.

  • Create a new function.
  • Define the new function.
  • Add the new function to the existing sequence.

17 of 18

If you have more time…

  • Create more functions for the dinosaur.
  • Add a new sprite and create a function.
  • Change the backdrop to create a new scene.

18 of 18

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.