Hey Guys,
I am practicing my javascript on codewars, and I keep getting a “NaN” at the end of my answer whenever I run my code. Can’t seem to figure what is wrong. Here is my code and the information on the problem. Appreciate the help!
const squareDigits = (num) => {
let numStr = num.toString().split(" ");
let newNum = " ";
for(let i = 0; i <= numStr.length; i++){
newNum += numStr[i] * numStr[i];
}
return newNum;
}
squareDigits(12345);
Welcome. In this kata, you are asked to square every digit of a number.
For example, if we run 9119 through the function, 811181 will come out, because 92 is 81 and 12 is 1.
Note: The function accepts an integer and returns an integer