Page doesn't detect my answer as right in the "use Recursion to Create a Range of Numbers" challenge

Tell us what’s happening:
for what the console.log() function returns my code is working and giving the right answer but for some reason when I run the test it tells me that it’s wrong. anyone know why this is happening? I don’t know if it’s for a mistake on my code that i"m not seeing or if there is a probleme with the page.
sorry for writing mistakes english is not my first language.

Your code so far

const vector = [];
function rangeOfNumbers(startNum, endNum) {
for (var i = startNum; i <= endNum; i++){
return vector;

var i = startNum;
if (i == endNum){

} else{
rangeOfNumbers(startNum+1, endNum)


console.log(rangeOfNumbers(1, 5));
//console.log(rangeOfNumbers(6, 9));
//console.log(rangeOfNumbers(4, 4));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 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.


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

thanks, but any tip on how to avoid the variable to reset each time?
This way if I use recursion it resets every time and it only shows the last value.

you need to do something with the value returned from the function call inside the function

ok, i’ll try that. one last thing. do you think i shoud try to do it with ount any variable, local o global? or that would not be posible?

you could do it without a variable, or you could do it with a variable (local! can’t be global)
it depends on the method of your choice
if it works, it works

ok, thank you for your time!

If you remove the console.log calls to the function, the code should pass. Although, refactoring the code to not use a global is a good idea anyway.

thanks. I’ll try to refactor the code.