I need help here..pleasee

Cuéntanos qué está pasando:
Describe tu problema en detalle aquí.

  **Tu código hasta el momento**

function sum(arr, n) {
// Cambia solo el código debajo de esta línea
function sum(arr, n) {
if(n<=0) 
  return arr[0];
  
} else {
  return sum(arr, n - 1) + arr[n - 1];

}

// Cambia solo el código encima de esta línea

  **Información de tu navegador:**

El agente de usuario es: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36

Desafío: Reemplaza bucles usando recursión

Enlaza al desafío:

Seems like you are declaring the function twice. You should only declare once and call it the other times.

function sum(arr, n) {
// Cambia solo el código debajo de esta línea
function sum(arr, n) {```
2 Likes

Hi @paooof !

A few things.

No.1:
You got this part right which is the hardest part for most people

But the return statement here is incorrect

Think about what you need to return for the base case.

Also, in addition to writing the function twice it looks like you might be missing a couple of curly braces.

It is hard to tell because your code isn’t formatted.

But it might be easier to omit the curly braces for the if else statement or rewrite it with a ternary if you feel comfortable.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.