Tell us what’s happening:
Hello everyone. I know that here are alot of topics and alot of discussions running down because of recursion. I readed alot and tons of examples just confused me because I couldnt see the forest cause of the trees. Sometimes the simplest things are hardest to understand.
I understood that my function repeats hisself until the base case. After the base case my variable arr is now defined with an empty array which allows my function to unshift values into my existing empty array but how does my function know the values? where are the values stored that my function can go backwards to put the values into my array?
I am really sorry that I created a new topic but I thought its better to start over with my state of understanding and creating my own topic to fill the missing understanding.
Your code so far
// Only change code below this line
function countdown(n){
if (n < 1) {
return [];
} else {
const arr = countdown(n - 1);
arr.unshift(n);
return arr;
}
}
// Only change code above this line
console.log(countdown(5))
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 OPR/99.0.0.0
Challenge: Basic JavaScript - Use Recursion to Create a Countdown
Link to the challenge:
