Tell us what’s happening:
What’s wrong in my solution code, results are correct but not letting pass this challenge?
Your code so far
// Only change code below this line
var myTest = [];
function countdown(n){
if (n <= 0) {
return myTest;
}myTest.push(n);
countdown(n-1);
return myTest;
}
// Only change code above this line
countdown(5);
console.log(myTest);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.193 Safari/537.36.
Your code contains global variables that are changed each time the function is run. This means that after each test completes, subsequent tests 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.
Example:
var myGlobal = [1];
function returnGlobal(arg) {
myGlobal.push(arg);
return myGlobal;
} // unreliable - array gets longer each time the function is run
function returnLocal(arg) {
var myLocal = [1];
myLocal.push(arg);
return myLocal;
} // reliable - always returns an array of length 2
Please do not create duplicate posts. You already have a topic open for this same question. I will close the other topic so @JeremyLT can assist you here.