One of my code is reversed but why is it wrong?

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

  **Your code so far**

function rangeOfNumbers(startNum, endNum) {
if (endNum === startNum) {
  return [startNum];
}
else {
  var range = rangeOfNumbers(startNum, endNum - 1);
  range.push(endNum);
  return range;
}
}
console.log(rangeOfNumbers(1, 5));

the code above is the correct code
but why below code is wrong ?

function rangeOfNumbers(startNum, endNum) {
  if (startNum === endNum) {
    return [startNum];
  }
  else {
    var range = rangeOfNumbers(startNum, endNum - 1);
    range.push(endNum);
    return range;
  }
}

can someone tell me why the code is wrong ?

  **Your browser information:**

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

Challenge: Use Recursion to Create a Range of Numbers

Link to the challenge:

Hi @anwararya849 !

I just ran both sets of code and they both work.
What error messages are you getting?

1 Like

Previously the code didn’t work, I just tried again and it worked. I don’t know why, but thank you
:smiley: