Recursion to Create a Countdown problem

Tell us what’s happening:
I’m passing all the tests except for “You should use recursion to solve this problem.”

Your code so far


//Only change code below this line
function countdown(n){
return n > 0 ? [n].concat(countdown(n - 1)) : [];
}
console.log(countdown(5)); // [5, 4, 3, 2, 1]

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.2 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

I don’t think the exercise recognizes the recursion being called from the ternary operator. You might try using an actual if, then and see if it fixes the issue.

1 Like