N
N
NoNIDs2018-08-19 09:36:05
JavaScript
NoNIDs, 2018-08-19 09:36:05

How to create multiple number counters in arrays?

You need to create a score counter for three players. I decided to calculate them by adding the scores in an array ( [1, 3, 1, 2] like this ). I looked on the Internet for a counter of numbers in an array and started using it, but the problem is that there are 3 counters in the whole code, and only the last array is calculated. Tell me how you can fix this problem, or maybe there is an alternative for this task.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ixon, 2018-08-19
@ixon

https://codepen.io/anon/pen/dqbvmg

var myarray = [1,3,1,4];
var score = 0;
for(var i = 0;i<myarray.length;i++){
score+=myarray[i];
}
alert(score)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question