Tell us what’s happening:
Tell me please, what is wrong with my code
function countdown(myArray, n){
if (n == -1) {
return [];
} else if (n > 1) {
myArray = countdown(myArray, n-1);
myArray.unshift(n);
return myArray;
}
}
mistake - ReferenceError: Can’t find variable: myArray
Your code so far
//Only change code below this line
function countdown(myArray, n){
if (n == -1) {
return [];
} else if (n > 1) {
myArray = countdown(myArray, n-1);
myArray.unshift(n);
return myArray;
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.1 Safari/605.1.15
.
Challenge: Use Recursion to Create a Countdown
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-countdown