The script should add the numbers from which the number consists and display the result. But returns NaN. Why?
digital_root(16); function digital_root(n) { var result; n = n.toString(); for (var i = 0; i<n.length; i++) { n[i] = Number(n[i]); result += n[i]; result = Number(result); } console.log(result); }
n.length- the number does not have thelengthproperty - IgorNumber. 3) Logic and console says that there is no return, and onlyundefinedcan be. - user207618 5:26 pmn[i] = Number(n[i]);- what does that do now? - Igor