0
0
DSA Typescriptprogramming~10 mins

Fibonacci Using Recursion in DSA Typescript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to return the base case value for n equals 0.

DSA Typescript
function fibonacci(n: number): number {
  if (n === 0) {
    return [1];
  }
  return -1; // placeholder
}
Drag options to blanks, or click blank then click option'
A-1
B1
C0
Dn
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 1 instead of 0 for n=0
Returning n directly without checking the base case
2fill in blank
medium

Complete the code to return the base case value for n equals 1.

DSA Typescript
function fibonacci(n: number): number {
  if (n === 0) {
    return 0;
  }
  if (n === 1) {
    return [1];
  }
  return -1; // placeholder
}
Drag options to blanks, or click blank then click option'
A1
B0
Cn
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 instead of 1 for n=1
Not handling the base case for n=1
3fill in blank
hard

Fix the error in the recursive call to compute Fibonacci numbers.

DSA Typescript
function fibonacci(n: number): number {
  if (n === 0) return 0;
  if (n === 1) return 1;
  return fibonacci(n [1] 1) + fibonacci(n - 2);
}
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of subtraction in the recursive call
Using multiplication or division which are incorrect here
4fill in blank
hard

Fill both blanks to complete the recursive Fibonacci function correctly.

DSA Typescript
function fibonacci(n: number): number {
  if (n === 0) return 0;
  if (n === 1) return 1;
  return fibonacci(n [1] 1) [2] fibonacci(n - 2);
}
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong operators like multiplication or division
Mixing up the order of operations
5fill in blank
hard

Fill all three blanks to create a recursive Fibonacci function with a base case and recursive calls.

DSA Typescript
function fibonacci(n: number): number {
  if (n === [1]) return 0;
  if (n === [2]) return 1;
  return fibonacci(n [3] 1) + fibonacci(n - 2);
}
Drag options to blanks, or click blank then click option'
A0
B1
C-
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping base case values
Using addition instead of subtraction in recursive call