B4Coder

🪆 Recursion · Mission 3 of 5

➕ Add Up to n

1 + 2 + … + n: the sum up to n is n plus the sum up to n - 1, and the sum up to 0 is 0.

Your mission

  1. Make a Function sumTo, given n. If n == 0, Return 0. Otherwise Call sumTo(n - 1) into rest, and Return n + rest.
  2. Main: Ask for n, Call sumTo(n) into total, and Tell "Total: " + total.

Getting the mission ready…