Basic JavaScript - Use Recursion to Create a Range of Numbers

Tell us what’s happening:
I tried this code on an online interpreter and it does give the required output yet its not able to pass the challenge

Your code so far

function rangeOfNumbers(startNum, endNum) {
  if (startNum == endNum){
  return [endNum];
  }
  arr = rangeOfNumbers(startNum+1,endNum);
  arr.unshift(startNum);
  return arr;
}



Your browser information:

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

Challenge: Basic JavaScript - Use Recursion to Create a Range of Numbers

Link to the challenge:

here are the errors you should be seeing

// running tests
Your function should return an array.
rangeOfNumbers(1, 5) should return [1, 2, 3, 4, 5].
rangeOfNumbers(6, 9) should return [6, 7, 8, 9].
Global variables should not be used to cache the array.
// tests completed

Try to tackle one of these at a time.
For eg. The last sentence “Global variables…”
What do you think this is referring to?

1 Like

ohhhhhhhhhhh thanku so much for not giving away the answer, and yeah gotcha it worked!!!

1 Like