0
How do I sum up the value in the arrays? (for my code project)
For example the input: 2 4 3 the first value represents the 'level', also the size of the array to be created, the next 2 inputs is the points they gained for passing 2 levels... how to sum up them and become 7??
3 Answers
+ 2
So first value is input and it shows number of levels?
Then you have an array whose length is number of levels?
Then you get 4 points for passing level 1 and 3 points for passing level 2?
so you have
let arrayLevel=[];
now you can add your level points to array.
arrayLevel.push(4);
arrayLevel.push(3);
Then create variable for sum
let sum=0;
And then you iterate through array
(fet i=0;i<arrayLevel.length;i++){
sum+=arrayLevel[i];
}
console.log(sum);
+ 2
Thank you so much for the reply, it works :)