Tell us what’s happening:
Not too sure why the code falls into an infinite loop. Can anyone help point me in the right direction why? Notice when this is console.logged(), at least one of the outputs is the “right” solution to the countdown problem but I don’t understand how to interpret the recursion to figure out why multiple circular loops form.
Your code so far
// Only change code below this line
var arr = [];
function countdown(n){
if (n < 1){
return [];
}
else if (n === 1){
return 1;
}
else{
arr.push(n)+arr.push(countdown(n-1));
console.log(arr);
return;
}
}
// Only change code above this line
console.log(countdown(4));
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0
.
Challenge: Use Recursion to Create a Countdown
Link to the challenge: