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

Tuesday

// Steps with names

Tuesday: Assembly Line

Rocket wants to cook fish for dinner with a grown-up. He has four small functions: wash, cut, cook, and plate. "I'll start cooking right now!" he says.

Raven smiles. "Wait. What do you notice about your hands?" Rocket looks down. "Oh. They are muddy from the garden."

Nova glows. "Each function is one stop on a line. Think about which stop comes first." Let's help them call the functions in order.

An assembly line is a chain of small functions. Read the line below.

function wash():    soap hands, rinse, dry
function cut():     slice into 4 pieces
function cook():    fry until cooked through
function plate():   put on a clean plate

Make dinner!

Write the four function calls IN ORDER to cook a fish.

1. ____________()
2. ____________()
3. ____________()
4. ____________()

Functions in a Chain

Big jobs are often a chain of small functions. Each one does one job well.

The order of the calls still matters, just like in Week 1.

function dig():     dig a small hole
function plant():   drop in a seed
function cover():   cover it with soil
function water():   pour on some water
PLANT WITH FUNCTIONS
  • Read the question.
  • Tap your answer.
Which call comes first?
Which call comes right after plant()?
Raven plants 3 seeds. How many times does she call plant()?
For 3 seeds, how many calls happen in all?
Rocket calls water() once for each of 5 seeds. How many water() calls?
One seed needs 4 calls. How many calls for 2 seeds?
To plant flowers instead of beans, which function would you change?
StatementTrue or false?
Each small function should do one job.?
The order of function calls never matters.?
You can call the same function many times.?
A chain of small functions can finish a big job.?
WHY THIS EXERCISEProgrammers build big programs from small functions in the right order.
SEND A LETTER WITH FUNCTIONS
  • ?mail_it()
  • ?fold_letter()
  • ?seal_envelope()
  • ?put_in_envelope()
  • ?write_letter()
WHY THIS EXERCISEFunction calls run in order, top to bottom, like any other steps.
Try it
Pick a chore, like setting the table.
Break it into three small functions with names.
Act out each call in order.
Try Without Paper
Pick a chore. Name 3 small functions inside it.
Example: clean_room() = pick_up() + dust() + vacuum().
← Monday