Use recursion to create a range of numbers someone please help

Tell us what’s happening:
Describe your issue in detail here.
i tried to add new solution to this code but it failed

  **Your code so far**

let arr =[];


function rangeOfNumbers(startNum, endNum) {
if (endNum-startNum0<0) {

return arr;
} else {
arr.push(endNum);
return  rangeOfnumbers((startNum+1),endNum);
}
}

  **Your browser information:**

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

Challenge: Use Recursion to Create a Range of Numbers

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.

Example:

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

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

In this case, the way to fix this is to switch from faux-recursion to true recursion that uses the return value from each function call.

no my format should change and look like the example you given me?
I already have let arr =; in my code

I’m asking if should I change My format of my code to look like the example you gave me ?

For this function to work, you must not declare a global variable like that.

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