Basic JavaScript - Use Recursion to Create a Range of Numbers

Tell us what’s happening:
Can anyone please correct me? this code gives the same output
Your code so far

function rangeOfNumbers(startNum, endNum) {
  if (startNum > endNum) {
    return [];
  } else {
let x =[];
    x.push(startNum);
document.write(x);
    rangeOfNumbers(startNum + 1, endNum);
  }
  
}

Your browser information:

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

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

Link to the challenge:

You are not returning anything.

Use the base case return as the array to push to.

If you push the startNum the array elements will be in the wrong order.

Don’t use DOM methods in the tests.

1 Like

Thank you very much and it was a great help :heart: :heart:

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