Use Recursion to Create a Range of Numbers JS

Tell us what’s happening:
Describe your issue in detail here.

i am not able to get why this would not be correct?
Your code so far


function rangeOfNumbers(startNum, endNum) {
if (startNum === endNum){
    return [startNum];
}
else {
  const arr = rangeofNumbers(startNum+1, endNum); 
  arr.push(endNum);
  return arr;
}
};
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36

Challenge: Use Recursion to Create a Range of Numbers

Link to the challenge:

or this one?

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

Concerning your first code, you forgot to capitalize the “O” in rangeOfNumbers when making the recursive call. Unfortunately, the FCC console doesn’t show you this error but if you have the browser console open you’ll see it.

But even after you fix that it will still not work. My suggestion would be to put a console.log right before the return in the else block:

console.log(arr);
return arr;

I think you’ll see what the problem is right away :slight_smile:

1 Like

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