Skip to content
Your progress

Checking your sign-in…

Who's learning?

Each profile keeps its own read lessons, badges, streak, and practice scores on this device.

Lesson 4 of 11

One call inside another

Show on a big screen

6 min

Text size

One cloth bag holds the morning fares. Another holds the evening fares. One line finds which bag has the bigger total.

max(total(morning), total(evening))
Step 1 of 4
  1. max(total(morning), total(evening))
  2. total(morning) finishes first: 30.
  3. total(evening) finishes next: 34.
  4. max picks the larger: 34.

Press the button below. Watch each call turn into a number.

Loading lab…

The rule

The list morning holds 8, 6, 10 and 6 rupees. The list evening holds 12, 8, 6 and 8.

total adds up a bag and hands back the sum. max takes two numbers and hands back the larger.

A call is a value. So a call can sit inside another line. The inside call runs first. It hands its value up. Only then does the outer line have what it needs.

`` max(total(morning), total(evening)) ``

  1. total(morning) runs all the way through. It gives 8 + 6 + 10 + 6 = 30.
  2. total(evening) runs. It gives 12 + 8 + 6 + 8 = 34.
  3. max(30, 34) runs. It gives 34.

So the evening bag has the bigger total, 34.

Try the lab to finish this lesson.