ArraySum issue that I've been working on

I am trying to get my arraySum function to return true if say I have this array:

//return true if 1+2+4+6=13
console.log(ArraySum([1,2,4,6,13]));

And I am trying to get my arraySum function to return false if I have this array:

//return false if 1+2+4+34 =39 !=22

console.log(ArraySum([1,2,4,34,22]))

I think I have the structure of this code correct, I just think the return values are in the wrong place and I don’t know where to put my return values.

My code is laid out here:https://codepen.io/noblegas/pen/GRgrraK

if you put return statements inside the loop of which one will always execute , then the loop will never go after the first iteration as a return statement will break from the function. you can’t put the if/else inside the loop.

so what do you suggest that I do?

don’t put it inside the loop, put it somewhere else

the total remains in the loop, but put the if/else if statements outside the loop?

you have declared total inside the function, not inside the loop, so you can use the variable anywhere in the function

Your suggestion worked for me. Thanks for your help.