Checking the recursion code

I am able to get the output according the needs but it is not executing , can anyone check what is wrong with the code ???

// Only change code below this line
let array = [];
function countdown(n){

  return array;
}else {
return [];
// return;
// Only change code above this line

  **Your browser information:**

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

Challenge: Use Recursion to Create a Countdown

Link to the challenge:

It appears you are declaring a variable called array outside of your function (let array = [];). Although it may work having a function that modifies a global variable, in this case you’re function should be building up the array, and then returning it, not just adding to a variable declared outside of the function scope. Check the example within the challenge, you can see there is no global variable needed.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.