function sum(arr, n) {
// Only change code below this line
function sum(arr, n) {
if (n <= 0) {
return 0;
} else {
return sum(arr, n - 1) + arr[n-1];
}
}
// 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/108.0.0.0 Safari/537.36 Edg/108.0.1462.54
Challenge: Basic JavaScript - Replace Loops using Recursion
I strongly recommend against looking at anybody else’s solutions until your code works. This is the part of the curriculum where problems start being less about syntax and more about problem solving.
I really recommend talking to other people when you’re stuck instead of looking at other people’s solutions. There is always time to look up other solutions after you get a working code of your own!