The result of this script is not the sum of the squares of the digits of a number, the first function works fine, I guess the problem is in the second
function nToArray(a) {
var res=[];
var s =a.toString();
for(i=0;i<s.length;i++){
res[i]=s.charAt(i);}
return res;
}
//var a ="hola";
//document.write(a.length);
alert(nToArray(562));
function addSq(b){
var c=nToArray(b);
var z=0;
var i;
for (i=0;i<=c.length;i++){//here
z+=((parseInt(c[i]))^2);}
return z;
}
alert(addSq(81));
For 81 I get 15, I don't get it.