Last recursion exercise

Tell us what’s happening:
Hi

Can someone explain please why my code returns 1 for every input?
Your code so far


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

}


}
console.log(rangeOfNumbers(0, 0))
  

  **Your browser information:**

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

Challenge: Use Recursion to Create a Range of Numbers

Link to the challenge:

there is no recursion and push returns the length of the array

1 Like

This function has no recursion. I would expect it to only ever return an empty array or the length of an array with one number inside.

At least I didn’t get an error. Thanks for getting back. Il try again.

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