Chapter 02 - Lesson 01

Recursion as a Repeating Rule

Use nested boxes and a call stack to feel what a recursive call does before drawing anything.

Concept explanation

Recursion means a rule calls itself again with a smaller version of the problem. The base case is the stop sign. Without it, the calls keep piling up.

Try it

Use nested boxes and a call stack to feel what a recursive call does before drawing anything.

Code fragment

function countDown(n) {
  if (n === 0) return "done";
  return countDown(n - 1);
}

What to observe

  • Each nested box is another call.
  • The depth slider changes how many calls can appear.
  • The smallest problem is where recursion stops.

Small challenge

Set depth to 6 and count the nested calls from the outside inward.