Comet writes a new procedure called checkPlant. It decides whether a plant needs water.
She calls it three times, once for the tomatoes, once for the basil and once for the beans.
"Same procedure," she says, "three different answers."
Wren points at the word level inside the parentheses. "Then where does level get its value?"
Comet points to the calls. "From the number I send each time."
Nova projects two glowing labels, one over the definition and one over a call.
"Interesting," she says. "Those two things have two different names. Can you find out what they are?"
Parameters are the input variables of a procedure. They are named when the procedure is written.
Arguments are the values given to the parameters when the procedure is called.
Using parameters lets one procedure be reused with many different input values.
PROCEDURE checkPlant(level)
{
IF (level < 30)
{
status ← "needs water"
}
ELSE
{
status ← "all good"
}
RETURN(status)
}
tomatoStatus ← checkPlant(25)
basilStatus ← checkPlant(64)
beanStatus ← checkPlant(30) A procedure that returns a value works like an expression. The call is replaced by the value it returns.
In the line below where lightAverage gets average(lightReadings), lightAverage stores whatever average sends back.
lightReadings ← [80, 90, 70] lightAverage ← average(lightReadings) tempAverage ← average([20, 22, 24, 22])
| Statement | True or false? |
|---|---|
| A parameter is named when the procedure is written. | ? |
| An argument is the value passed in when the procedure is called. | ? |
| A procedure with a parameter can work with only one input value. | ? |
| A call to average can be stored in a variable. | ? |
Nice work. Tomorrow in Beacon Lab you will split all of Beacon into modules.