A recursive function solves a problem by calling itself on a smaller version of the problem, like a set of Russian dolls. Every recursive function needs a base case, the smallest doll, where it stops.
🎯 Write factorial(n): the product of all whole numbers from 1 to n. So factorial(5) is 5 × 4 × 3 × 2 × 1 = 120, and factorial(0) is 1. Use recursion: factorial(n) is n × factorial(n - 1).
Output
Press Run to see what your code prints.Lesson 2 of 16 · Lesson map · Your code runs safely inside this page and is never sent anywhere.