Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Salesforce Exam Javascript Developer I Topic 1 Question 66 Discussion

Actual exam question for Salesforce's Javascript Developer I exam
Question #: 66
Topic #: 1
[All Javascript Developer I Questions]

A developer is required to write a function that calculates the sum of elements in an

array but is getting undefined every time the code is executed. The developer needs to find

what is missing in the code below.

Const sumFunction = arr => {

Return arr.reduce((result, current) => {

//

Result += current;

//

), 10);

);

Which option makes the code work as expected?

Show Suggested Answer Hide Answer
Suggested Answer: A

Contribute your Thoughts:

Judy
1 months ago
Is it just me, or does this question smell like a trick? I'm going to go with option A and hope for the best. Alternatively, I could just ask the developer to try turning it off and on again.
upvoted 0 times
...
Chaya
1 months ago
This reminds me of that time I tried to debug my code while blindfolded. Spoiler alert: it didn't end well. Option C looks promising, but I'd better double-check my work.
upvoted 0 times
Lavonna
9 days ago
I agree, let's double-check before making any changes.
upvoted 0 times
...
Yesenia
11 days ago
I think option C is the correct one.
upvoted 0 times
...
...
Delisa
2 months ago
Wait, what? Undefined? That's a classic JavaScript conundrum. I'd say option D is the way to go, but who knows, maybe the developer just needs more coffee.
upvoted 0 times
Dudley
5 days ago
Let's hope the developer tries that and gets it working!
upvoted 0 times
...
Ceola
6 days ago
Yeah, returning the result at the end of the function should give the correct sum.
upvoted 0 times
...
Brett
11 days ago
I think you're right, that should fix the issue.
upvoted 0 times
...
Jess
1 months ago
Option D) Replace line 05 with return result;
upvoted 0 times
...
...
Katina
2 months ago
But if we look at the code, it seems like line 04 needs to be fixed to update the result correctly.
upvoted 0 times
...
Lynna
2 months ago
Aha! I bet the problem is with the curly braces. They seem to be a bit out of place. Let me try option B and see if that fixes it.
upvoted 0 times
Justine
1 months ago
User2: Try option B and see if that fixes it.
upvoted 0 times
...
Cornell
1 months ago
User1: I think the issue is with the curly braces.
upvoted 0 times
...
...
Marge
2 months ago
I disagree, I believe option D is the right one.
upvoted 0 times
...
Raul
2 months ago
Hmm, I think the issue is with the reduce function. The initial value should be passed as the second argument, not in the callback function.
upvoted 0 times
...
Katina
2 months ago
I think the correct option is B.
upvoted 0 times
...

Save Cancel