0
I dont want this code to show me NaN can someone help me?
Const marks = [12, 13, 15, 17] Let sum =0 For (let i=0; i<=marks.length;i++){ sum += marks[i] } Console.log(sum)
2 Respuestas
+ 5
amir hosein kazazi
As array index start from 0 and you have 4 elements so your index would be 0 1 2 3
But you are trying to access 4th index which has nothing so you get NaN.
So change i <= to i <
+ 2
One tip, use console.log(i) inside loop, or in any code where have unespected output or error.
So you can see what are your data