Chapter 7, section 1

Directions: For this part, you are allowed 30 minutes to write a passage

Code implementation

    // Calculate the factorial of 4 recursively

    // Write a function that calls itself internally to form recursion
    function factorial(n) {
      // This function computes n! , n! It's n times n minus 1 factorial.
      // This is the exit of recursion. If you calculate the factorial of 1, you can return 1 without recursion
      if (n == 1) return 1;
      // Return n* (n-1)!
      return n * factorial(n - 1);
    }
    var result = factorial(4);
    alert(result);
Copy the code