← Back to course
Code Crew G3 / Week 05 / Crew Quest
6/6
Week 05 Β· Functions

Crew Quest

// Steps with names

Crew Quest: Name Your Day

Raven makes a list of her day. Wake up, eat breakfast, walk the dog. "Each one has lots of small steps," she says.

Rocket grins. "Let's give each one a function name!" He joins the words with a little low line, like programmers do.

Nova adds a hint. "Some functions need an input. Brushing teeth needs a toothbrush." Let's help them name five things from today.

Pick FIVE things you do today. Give each one a function name.

Use lowercase_with_underscores(). Programmers love this.

1. ____________________ ()
2. ____________________ ()
3. ____________________ ()
4. ____________________ ()
5. ____________________ ()

Now list which one has a parameter (input)

Example: brush_teeth(toothbrush). The toothbrush is the input.

My function with an input:
Crew Brag Box
Read your function names to a grown-up. They will laugh. That's OK.
β˜… Earn a star if any of your names made someone else GUESS what they do.

Week 5 Recap

  1. FUNCTION = a named group of steps.
  2. CALL the function by writing its name with ().
  3. PARAMETERS are inputs you hand in.
  4. Functions can call other functions.
Try This Without Paper
1. Tell a parent: 'Run my GO_TO_SCHOOL() function.'
2. Ask a sibling to call your CLEAN_ROOM() function. Did they laugh?
3. Spot a function in a song (chorus = a called function).
β—‡ FUNCTION MACHINE
One person is a function machine called double().
The other person says a number as the input.
The machine says the output: the number plus itself.
Swap jobs. Invent a new machine, like add_three().
WEEK 5 REVIEW
  • Read the question.
  • Tap your answer.
What is a function?
What is a parameter?
double(n) says n + n. What does double(6) say?
add_three(n) says n + 3. What does add_three(5) say?
StatementTrue or false?
You call a function by writing its name with ( ).?
A function can call another function.?
Function names should tell what the steps do.?
A function must be rewritten each time you use it.?
WHY THIS EXERCISEFunctions are how programmers reuse good steps.

Coming up next…

Week 6: DEBUGGING. Finding the broken step.

← Friday