Wrong function for checksum

Hi guys,

does anyone know why I can’t calculate a checksum like that?

function quersumme (zahl){
var sum =0;
var i=0;

while (i<zahl.length){

sum = sum + zahl.substr(i,1);

return sum;

I think

var sum = “” //Not zero, instead empty.

and you have to call the function. For example:

console.log(quersumme(“Valami Amerika”));

or something like this.
It is works for me.

Hm. For me it doesn’t work. Have you tried to a´calculate a checksum with my code? E.g. quersumme(456) should be 15 as a result.

I think … you can use the substr() method only on strings… so if you have to use substr() method firstly you have to convert the number to string. Than selelct the “numbers/letters” one-by-on and convert back to number and add to sum.
In your code the

var sum = 0;

line is right. //Sorry.//

**** Spoiler Alert ****

Of course, you are right. It worked :slight_smile: Thank you very much!