Tell us what’s happening:
The code I have here is correct to case n=3 and n=4, but it is not correct for n=5 for some reason. Can someone help identify the error here? (Please ignore the “infinite loop” btw)
Code
function digitnPowers(n) {
var totalSum = 0;
for(let i = 2**n; i<9**(n+1); i++) {
var numList = String(i).split("");
var currNum = i;
for(let j = 0; j<numList.length; j++) {
currNum -= parseInt(numList[j])**n;
}
if(currNum===0) {
totalSum += i;
}
}
return totalSum;
}
digitnPowers(5);