Tell us what’s happening:
I think the code is buggy, since i am using recursion and it is still asking me to use recursoin in order to get the lesson.
by the way thanks to the creators of this site for including extra lessons.
Your code so far
js
function sum(arr, n) {
// Only change code below this line
if (n <= 0) {
return arr[0];
} else {
return sum(arr, n - 1) + arr[n];
}
// Only change code above this line
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:69.0) Gecko/20100101 Firefox/69.0.
It doesn’t like that the function call is inside of an if statement. Move that function call to the end of the function body, and things should be better.
function sum(arr, n) {
// Only change code below this line
if (n <= 0) {
return arr[0];
}
return sum(arr, n - 1) + arr[n];
// Only change code above this line
}
I’ve just checked, and here’s how it’s testing if you’re using recursion:
{
text: "You should use recursion to solve this problem.",
testString: "assert(removeJSComments(sum.toString()).match(
/sum\(.*\).*\{.*sum\(.*\).*\}/s)
);"
}
So it doesn’t matter if the call to the sum function is in an if statement or not. You just need to call that sum function somewhere in the function for that test to pass.
Your code is good. I recommend following @ ieahleen’s advice.
hey guys, I believe the problem is the maintenance on the site. I cant sign in on chrome, so i think i just have to wait to keep coding. Thanks for all the help
I am also not able to log in. But the challenges should work even without log in, as declared (and it is working for me). So that cannot be a problem, i think.