0
Why this code is returning undefined?
2 Respostas
+ 5
returns undefined because the variable you want to return is not recognized outside the for block. and your checkid function doesn't do what you really want, the for condition is always false, the num is incremented by strings. to fix this do this:
function checkId(customerId) {
var num = 0;
for (let i = 0;i < customerId.length;i++){
num += parseInt(customerId[i]);
};
return num;
}
+ 1
Erlenio.RS thanks a lot.Your explanation leads me to right direction.