hi everyone, can you help me on how to solve this challenge of using a recursion to create a count down?
Hi there,
Can you edit your post and insert the lesson link?
I have edited it please
Hello and welcome to the freeCodeCamp community~!
If you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.
Thank you.
follow the picture as a guide and insert the lesson code.
this is the instruction: The function should use recursion to return an array containing the integers n
through 1
based on the n
parameter. If the function is called with a number less than 1, the function should return an empty array. For example, calling this function with n = 5
should return the array [5, 4, 3, 2, 1]
. Your function must use recursion by calling itself and must not use loops of any kind.
Which part is unclear for you? if you have problem with recursion in Javascript, check out this video: https://www.youtube.com/watch?v=k7-N8R0-KY4&t=447s
Thats my code but still it doesnt come out. what could be the problem:
Your code so far
// Only change code below this line
function countdown(myArray, n){
if (n <= 0) {
return;
} else{
myArray.push(n);
countdown(myArray, n-1);
}
}
// Only change code above this line
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0
.
Challenge: Use Recursion to Create a Countdown
Link to the challenge:
Hello there.
Do you have a question?
If so, please edit your post to include it in the Tell us what’s happening section.
The more information you give us, the more likely we are to be able to help.
If you do console.log(countdown(5));
You will see an error. Note that the tests only pass one argument to the function, but your function asks for two arguments.