Basic JavaScript - Use Recursion to Create a Countdown

Tell us what’s happening:

Honestly, the array in this function confuse me. How the result goes into the array?

Your code so far

// Only change code below this line
function countdown(n) {
  if (n < 1) {
    return [];
  } else {
    return [n] + countdown(n - 1);
  }
}
console.log(countdown(5));
// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36

Challenge Information:

Basic JavaScript - Use Recursion to Create a Countdown

Welcome to the forum @amirinaeem200

First you need to declare an array.

You can use the else block given in the instructions as a guide to structure the code.

Happy coding