Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What is a recursive function?

View

Which of the following is required for a recursive function to avoid infinite recursion?

View

What will the following code output? function countdown(n) { if (n === 0) return; console.log(n); countdown(n - 1); } countdown(3);

View

How can you define a recursive function in JavaScript?

View

What will be the output of this code? function sum(n) { if (n === 0) return 0; return n + sum(n - 1); } console.log(sum(5));

View

What is a potential risk when writing recursive functions?

View

What will the following code output? function factorial(n) { if (n === 1) return 1; return n * factorial(n - 1); } console.log(factorial(4));

View

Which of the following is true about recursion?

View

What will be the output of this code? function fib(n) { if (n <= 1) return n; return fib(n - 1) + fib(n - 2); } console.log(fib(5));

View

What is one common use case for recursive functions in JavaScript?

View

What is a recursive function?

A function that returns itself
A function that calls itself
A function that creates new functions
A function that runs indefinitely

Which of the following is required for a recursive function to avoid infinite recursion?

A global variable
A base condition
A return value
A timeout

What will the following code output? function countdown(n) { if (n === 0) return; console.log(n); countdown(n - 1); } countdown(3);

3, 2, 1
3, 2, 1, 0
3
Error

How can you define a recursive function in JavaScript?

Using a for loop
Using a function that calls itself
By returning an anonymous function
Using the recursion keyword

What will be the output of this code? function sum(n) { if (n === 0) return 0; return n + sum(n - 1); } console.log(sum(5));

15
10
5
Error

What is a potential risk when writing recursive functions?

Stack overflow due to too many function calls
Slower performance than loops
Variables being overwritten
Infinite loops

What will the following code output? function factorial(n) { if (n === 1) return 1; return n * factorial(n - 1); } console.log(factorial(4));

24
16
4
Error

Which of the following is true about recursion?

It requires a for loop to function properly
It can sometimes be replaced by loops
It never ends unless a loop is used
It can only be used with numbers

What will be the output of this code? function fib(n) { if (n <= 1) return n; return fib(n - 1) + fib(n - 2); } console.log(fib(5));

5
8
3
13

What is one common use case for recursive functions in JavaScript?

Manipulating the DOM
Iterating over arrays
Traversing tree-like data structures
Creating event listeners