I have a problem solving a sentence, the solution that I think makes sense has an error message
Did you make a recursive call to countDownRecursive() with count decremented?
countDownIterative() is a function that accepts a number and counts down to 0 using a loop.
Using what you know of recursion, create a recursive version of countDownIterative() by completing the function countDownRecursive() so that it uses recursion instead to count down.
Perhaps, you arenât matching the specifications in the instructions exactly. Looking at the exercise should offer some clues as to the nature of the issue.
Well, seeing as you provided the solution, the best I could do is explain whatâs happening.
Recursive functions are functions which call themselves somewhere in their function body. By calling themselves within themselves, they create recursive loops. Like iterative loops, recursive loops need conditions that cause them to stop looping, or else they would loop indefinitely. You may have already learned this if youâre presented with this challenge, but the ending conditions for recursive functions are often called the âbase caseâ.
With that said, letâs break the solution down:
function countDownRecursive(count) {
// here we establish the base case i.e. if count has reached 0, then we log and stop looping
if (count === 0) {
console.log(`Blast Off~!')
// next, we establish what happens if the base case has not been reached: we log out the current count and then call this function again with our current count decremented by 1
} else {
console.log(count)
countDownRecursive(count - 1)
}
}
Weâre at a bit of a disadvantage since in all fairness we should not be helping someone pass an exam. Itâs a solo effort intended to corroborate our level of development. Given the exam can be retaken, there is no harm in fumbling so long as we are aware of the question or questions that gave us difficulty. Likewise, there is no harm in reviewing and discussing the concept(s) involved, and practicing some more before taking the exam again.
We are in a position to discuss the recursion concept, but that should be a new topic. Try posting a question and see what the members respond with. Just donât post the exam question⌠We cannot give you the answer or any coaching.