I have an array with 3 indices for each student:
var students = [
['Toto', 4, 17],
['Titi', 11, 12],
['Tata', 12, 14]
];
I have to calculate the sum for each student. Except that, I must avoid the string.
My result obtained for the student Toto is 0 instead of 21.
I don't understand where the problem?
var students = [
['Toto', 4, 17],
['Titi', 11, 12],
['Tata', 12, 14]
];
var result = 0;
for (var i = 0; i < students.length; i++) {
if (typeof(students[i]) === "number") {
result += students[i];
}
console.log("Student " + students[i][0] + " has the result " + result);
}