Tell us what’s happening:
The code can not pass the last test.
I think the prevention of infinite loop is causing this.
How can I change my code to pass the tests.
Your code so far
function digitnPowers(n) {
var numbers = [];
var start = 2;
var added = 0;
while(true){
var Str = start.toString();
for(let i = 0; i<Str.length; i++){
added += Math.pow(Number(Str[i]),n)
}
if(added == start){
numbers.push(added);
}
added = 0;
start++;
}
return console.log(numbers);
}
digitnPowers(5);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.
Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/project-euler/problem-30-digit-n-powers/