Factorial Using Recursion
📖 Scenario: Imagine you are helping a friend who wants to calculate the factorial of a number. Factorial means multiplying a number by all the numbers below it down to 1. For example, 4 factorial is 4 x 3 x 2 x 1 = 24.
🎯 Goal: You will write a small program in TypeScript that uses a function calling itself (recursion) to find the factorial of a number.
📋 What You'll Learn
Create a variable called
num with the value 5Create a function called
factorial that uses recursion to calculate factorialCall the
factorial function with num and store the result in resultPrint the value of
result💡 Why This Matters
🌍 Real World
Calculating factorials is useful in math problems, probability, and computer science algorithms.
💼 Career
Understanding recursion helps in solving complex problems and is a common topic in programming interviews.
Progress0 / 4 steps