Basic JavaScript - Use Recursion to Create a Range of Numbers

Tell us what’s happening:
I don’t know why my recursion code doesn’t work. It said “RangeError: Maximum call stack size exceeded”. Can anyone tell what is problem?
Your code so far

function rangeOfNumbers(startNum, endNum) {
  if (endNum < startNum){return []
  } else {
    const myArray = rangeOfNumbers(endNum - 1);
    myArray.push(endNum);
    return myArray
  };
};
console.log(rangeOfNumbers(3, 10))

Your browser information:

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

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

Link to the challenge:

yo are calling rangeOfNumbers with only one argument, so the base case is never reached

oh I got it, thank you.

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