I got answer but Test Case is fail

Tell us what’s happening:
I don’t understand why my Test case fails even i got correct output in console.

Your code so far


var myArray = [];
function rangeOfNumbers(startNum, endNum) {
if(startNum <= endNum){
  myArray.push(startNum);
  rangeOfNumbers(startNum+1,endNum);
}
return myArray;
};

var arr = rangeOfNumbers(6,9);

console.log(arr);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0.

Challenge: Use Recursion to Create a Range of Numbers

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers

You declared myArray globally. This means each test will still have access to the value at myArray during each function call. myArray does not get reset after each test. Instead, it just grows. This is why you should not typically declare variables globally.

1 Like

If you remove the call to rangeOfNumbers you will pass the test.