Write a function digitsum that calculates the digit sum of an integer. The digit sum of an integer is the sum of all its digits.

PHOTO EMBED

Sun Dec 05 2021 19:46:36 GMT+0000 (Coordinated Universal Time)

Saved by @tolanisirius

function digSum(n) {
    let sum = 0;
    let str = n.toString();
    console.log(parseInt(str.substring(0, 1)));
    for (let i = 0; i < str.length; i++) {
        sum += parseInt(str.substring(i,i+1));
        
    }
    return sum;
}
content_copyCOPY

https://www.code-helper.com/answers/write-a-function-digitsum-that-calculates-the-digit-sum-of-an-integer-the-digit