Recursion problem

Tell us what’s happening:
although my code return exactly what is required, the computer doesnt accept it.
could u please help me why?

Your code so far

// Only change code below this line
var a=[]
function countdown(n){
   return [];
 return a;

// Only change code above this line
console.log(countdown(10)); // [5, 4, 3, 2, 1]

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36.

Challenge: Use Recursion to Create a Countdown

Link to the challenge:

Your code contains global variables that are changed each time the function is run. This means that after each test completes, subsequent tests start with the previous value. To fix this, make sure your function doesn’t change any global variables, and declare/assign variables within the function if they need to be changed.


var myGlobal = [1];
function returnGlobal(arg) {
  return myGlobal;
} // unreliable - array gets longer each time the function is run

function returnLocal(arg) {
  var myLocal = [1];
  return myLocal;
} // reliable - always returns an array of length 2
1 Like

for now, i can not imagine any other ways to solve this issue.
i will keep thinking about it
regards, thx for ur support

ok, let’s put it in this way:
the point of recursion is to use the returned value of the function itself.
In the way that you use the returned value of myFunc(n-1) as a starting point to get the returned value of myFunc(n)

try to take a look at the example code, and understand how that principle is applied there