Rocket writes the five toast steps on his tablet. Then he writes them again. And again! "My hand is getting tired," he says.
Raven looks at his lists. "What do you notice?" she asks. "Every list is the same," Rocket says.
Nova blinks her blue eyes. "Would you like a hint? A group of steps can have a name." Let's help them name the toast steps.
Every morning RAVEN does the same 5 steps to make toast. Instead of writing all 5 every day, Raven gives the steps a NAME: make_toast(). Now Raven just writes 'make_toast()' and the same 5 steps run.
function make_toast():
get bread
put bread in toaster
push the lever
wait until pop
add banana slices Writing the steps inside a function is called DEFINING it. Using its name is called CALLING it.
You define a function one time. Then you can call it as many times as you need.
function wave_hello():
raise your hand
wave 3 times
say hello
wave_hello()
wave_hello() | Statement | True or false? |
|---|---|
| A function is a group of steps with a name. | ? |
| You must write the steps again every time you call it. | ? |
| wave_hello() runs all the steps inside wave_hello. | ? |
| A function can only be called one time. | ? |