From logical view it looks fine. You could also try the ternary operator if you want to play around.

return n <= 0 ? 0 : sum(arr, n - 1) + arr[n - 1];

The first block is the if question. If its true is goes to the second block (starts whith ?) and if its false it goes to the third block (starts with :).

Answer from Athii on Stack Overflow
🌐
freeCodeCamp
forum.freecodecamp.org › guide
freeCodeCamp Challenge Guide: Replace Loops using Recursion - Guide - The freeCodeCamp Forum
February 22, 2020 - Replace Loops using Recursion Hints Hint 1: When n <= 0 sum(arr, n) returns 0. Hint 2: When n is larger than 0 sum(arr, n) returns sum(arr, n - 1) + arr[n - 1] Solutions: (Click to reveal) function sum(arr, n) { if(…
Discussions

Replace Loops using Recursion - Explained
Hey all, I wanted to share this, as I read through the previous posts and nothing mentioned my problem with understanding how this all works. Here is my code: function sum(arr, n) { // Only change code below this line if (n More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
2
June 1, 2021
Basic JavaScript - Replace Loops using Recursion
Everything was going great until “recursion” came into play and i think this was where things got mixed up for me hence why the countDown exercise is frustrating me presently, i have gone thru the breakdown explanation of recursion there but the correlation of how they make recursion possible ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
June 11, 2023
Replace Loops using Recursion
First Post here: I would love some feedback on whether my understanding of the solution to this challenge is correct. function sum(arr, n) { // Only change code below this line if (n More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
January 13, 2023
freeCodeCamp Challenge Guide: Replace Loops using Recursion - Guide - The freeCodeCamp Forum
Replace Loops using Recursion Hints Hint 1: When n (Click to reveal) function sum(arr, n) { if(n More on freecodecamp.org
🌐 freecodecamp.org
136
October 16, 2019
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Replace Loops using Recursion - JavaScript
October 29, 2023 - function sum(arr, n) { // Only change code below this line if (n
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Replace Loops using Recursion - Explained - JavaScript
June 1, 2021 - Hey all, I wanted to share this, as I read through the previous posts and nothing mentioned my problem with understanding how this all works. Here is my code: function sum(arr, n) { // Only change code below this li…
🌐
YouTube
youtube.com › watch
Replace Loops using Recursion - Free Code Camp - YouTube
This is a basic JavaScript tutorial where we replace loops using recursion. Recursion is quite difficult for me to get my head around in general.
Published   November 2, 2019
Find elsewhere
🌐
freeCodeCamp
forum.freecodecamp.org › code feedback
Replace Loops using Recursion - Code Feedback - The freeCodeCamp Forum
January 13, 2023 - First Post here: I would love some feedback on whether my understanding of the solution to this challenge is correct. function sum(arr, n) { // Only change code below this line if (n <= 0) { return 0; } els…
🌐
Usefulprogrammer
usefulprogrammer.org › home › blog › replace loops using recursion – free code camp
Replace Loops using Recursion - Free Code Camp - UsefulProgrammer.org
This is a basic JavaScript tutorial where we replace loops using recursion. Recursion is quite difficult for me to get my head around in general. Thank you for watching.
Published   December 1, 2022
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Replacing loops with recursion
March 9, 2020 - Cant seem to pass recursion test cant get second call to equal 2 can anyone help ? Your code so far function sum(arr, n) { // Only change code below this line if (n<=1){ return 0; } else{ return sum (arr, n - 1) + arr…
🌐
Connorocampo
connorocampo.dev › blog › replace-loops-using-recursion
Replace Loops using Recursion (Line-by-line Solution Explanation) | Connor Ocampo's Website
June 3, 2020 - This is a line-by-line code explanation of freeCodeCamp’s Replace Loops using Recursion module in their Basic JavaScript section.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Replace Loops Using Recursion Clarification - JavaScript
February 7, 2020 - Tell us what’s happening: I understand how basic function recursion works, the function is simply re-called within the function I understand that the function is calling itself and only when n <= 0 is false, then e…
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Replace Loops using Recursion Help Please - JavaScript
August 18, 2019 - I have so many questions here I don’t know where to start. I should say that I have done all the exercises up to this point but otherwise have had absolutely no experience with coding. Therefore it is entirely possible, …
🌐
ThisCodeWorks
thiscodeworks.com › basic-javascript-replace-loops-using-recursion-or-freecodecamp-org › 61f60402f273f000154c2ddd
Basic JavaScript: Replace Loops using Recursion | freeCodeCamp.org | thiscodeWorks
function multiply(arr, n) { if (n <= 0) { return 1; } else { return multiply(arr, n - 1) * arr[n - 1]; } } content_copyCOPY https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Basic JavaScript #103: Replace Loops using Recursion - JavaScript - The freeCodeCamp Forum
April 16, 2020 - function multiply(arr, n) { if (n <= 0) { return 1; } else { return multiply(arr, n - 1) * arr[n - 1]; } } In the base case, where n <= 0 , it returns 1. What is the purpose for, and resul…
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Replace Loops Using Recursion - Comprehension
February 19, 2021 - Hello, I have read other posts and watched various videos but am still stumped on comprehending the example code in this exercise. I understand the concept of recursion being a “reflection,” calling itself as a sort of “shortcut” from using loops in order to execute statements until ...