Preview:
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;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter