I want to add two numbers from range 10-99,for example:
Input:16
Output:1+6=7
Input:99
Output:18
function digital_root(n) {
var z = n.toString().length;
if (z == 2) {
var x = z[0] + z[1]
return x;
}
}
console.log( digital_root(16) );
Output from this code is NaN.What should I correct?
zis a number here, not a list or a string. So you are essentialy doingundefined + undefinedwhich correctly outputsNaNn[0]andn[1]?.lengththere.