Basic JavaScript - Use Recursion to Create a Range of Numbers

Tell us what’s happening:
why this code is not passing the tests even after giving correct output
Your code so far

let temp=[];
function rangeOfNumbers(startNum, endNum) {
return temp;
return rangeOfNumbers(startNum,endNum);
console.log(rangeOfNumbers(6, 9));
  **Your browser information:**

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

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

Link to the challenge:

Your code contains global variables that are changed each time the function is run. This means that after each function call completes, subsequent function calls start with the previous value. To fix this, make sure your function doesn’t change any global variables, and declare/assign variables within the function if they need to be changed.


var myGlobal = [1];
function returnGlobal(arg) {
  return myGlobal;
} // unreliable - array gets longer each time the function is run

function returnLocal(arg) {
  var myLocal = [1];
  return myLocal;
} // reliable - always returns an array of length 2

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