What is wrong ? Recursion to Create a Range of Numbers

Hello !! i need help i dont know what is wrong with this code ?

the exercise is Use Recursion to Create a Range of Numbers

Thanks for u help !

   **Your code so far**

let array = []
function rangeOfNumbers(startNum,endNum) {

if (startNum <= endNum) { 
 array.push(startNum)
 return rangeOfNumbers(startNum+1,endNum)
 } 
return (array);


 
};

console.log(rangeOfNumbers(6,9))


   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0

Challenge: Use Recursion to Create a Range of Numbers

Link to the challenge:

You shouldn’t use a global variable like this… It makes your function fragile and only work once.

Instead, you should use the return value of the recursive call. The recursive call should always return an array.

1 Like