Skip to content
Exit presentation

Computational Thinking III: Functions & Debugging

What you hand it, and what each end is called

A fare needs two answers. How many stops? Who is riding?

fare(stops, rider) waits for two values.
Step 1 of 4
  1. fare(stops, rider) waits for two values.
  2. fare(3, "adult") fills both slots.
  3. fare(2) fills only one.
  4. The run stops. It needs 2 values and got 1.

Read each card below. Tap Parameter or Argument.

Loading lab…

The rule

The call gives both answers. In fare(3, "adult"), there are 3 stops and an adult is riding.

In function fare(stops, rider), stops and rider start empty. A call fills them.

The name written in the brackets of the definition is the parameter. The value written in the brackets at the call is the argument.

A parameter is a name in the definition. An argument is a value in the call.

fare(3, "adult"); hands over 3 and "adult". The values fill the parameters in order. So stops is 3 and rider is "adult".

Where each word is written
WordWritten whereWhat it is
ParameterIn the definitionA name, empty until a call
ArgumentIn the callA value, handed over

Call fare(2) with one value, not two. Then rider has no value. In this language, the run stops with a message:

` fare needs 2 values, but you gave 1. `

Jump to lesson

This track

  1. 0 Start here
  2. 1 A name for a group of steps
  3. 2 What you hand it, and what each end is called
  4. 3 The value it hands back
  5. 4 One call inside another
  6. 5 A print in the middle
  7. 6 One line at a time
  8. 7 Predict, then run
  9. 8 Halve the hunt
  10. 9 The big picture
  11. 10 Track quiz

Other tracks