Tell us what’s happening:
Hi there, why when I run my code I see “InternalError: too much recursion” expression
What are my mistakes?
My code so far
// Only change code below this line
function countdown(n){
if (n < 1) {
return [];
} else {
var countDown = countdown(n);
countDown.push(n - 1);
return counDown;
}
}
console.log(countdown(5));
// Only change code above this line
// This is a function that return CountUp using Recursion
// function countup(n) {
// if (n < 1) {
// return [];
// } else {
// var countArray = countup(n - 1);
// countArray.push(n);
// return countArray;
// }
// }
// console.log(countup(5));
// This is a function that return CountUp using Recursion
Your browser information:
Challenge: Use Recursion to Create a Countdown
Link to the challenge: