function digitSum(y) { let sum = 0, x = String(y); for (let i = 0; i < x.length; i++) { sum += Number(x[i]); } return(sum) } // if alert(digitSum(123)), output is 6.