I am learning Javascript and I have this problem to raise the digits of the given number to the number of digits of the given number (ex 153 = 1^3+5^3+3^3). ^ should be **
I can’t figure out why sum does not increment with power, the times the number of digits the given number has.
let num = 153;
let digits = Array.from(String(num),Number);
console.log(digits);
for (let i=0;i<digits.length;i++){
let power = 0;
let sum = 0;
power = Math.pow(digits[i],digits.length);
sum += power;
console.log(sum);
}
The n how do i do it? I am sitting here for hours and i feel frustrated and stupid.
Edit: I have make the addition the times the digits, if there are 3 digits in the number then I have add the power of the number 3 times. How can I do that?