JavaScript Recursion — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Recursion lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Count down
easy10 minCount down from 3 to 1 with recursion, collecting the numbers joined by a dash.
- 2
Factorial
easy10 minWork out factorial of 5 with recursion.
- 3
Add up an array
easy10 minAdd every number in the array using recursion.
- 4
Count nested items
easy10 minCount every item in a nested list, however deep it goes.
- 5
Reverse a string
medium10 minReverse the word stream using recursion.
Find the bug(5)
- 1
Fix the wrong base case
easy8 minThe base case returns the wrong starting value.
- 2
Fix the value that never shrinks
easy8 minThe recursive call passes the same value, so nothing progresses.
- 3
Fix the missing recursive call
easy8 minNested lists are counted as one item instead of being opened up.
- 4
Fix the reversed join order
easy8 minThe characters are put back together the wrong way round.
- 5
Fix the base case checked too late
easy8 minThe list is read before checking whether it is empty.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace