Loop not adding last value only to the sum

Hi,

I hope you can help me with this. I’m trying to get the sum of all values after you click on the bottons. However, the loop is not adding the last value only. It’s taking the first value of the array, and then adding first and second value of the array when the function runs again.
Instead of doing 10 + 15 = 25, it’s doing 10 + 10 + 15 or 15 + 15 + 10.

Here’s the link to codepen: https://codepen.io/Polask1/pen/WNdGLEr?editors=0010

Never mind, I found the problem. The variable had to be included in the function.

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