Hi all, I’m really struggling to see what I’m doing wrong if someone could help please. I feel like this is quite basic but I’m super stuck!
I need to take a string (eventually this could include letters) and total it eg so ‘1,2 3’ = 6. I can split the string into an array but I can’t seem to then correctly apply a loop to create the sum total for me.
If I change it to an array manually the for loop works so I ‘think’ there is something going on between me splitting and the loop. thank you!
const string = '4,2,3,4,5,6,7,1,2,4';
let myString = string.split('');
let totalScore = 0;
for (i = 0; i < myString.length; i++) {
totalScore += myString[i];
}
console.log(totalScore);
//output 04,2,3,4,5,6,7,1,2,4