Tell us what’s happening:
This challenge involves using numbers up to 2**1000, so I decided to use BigInteger, but now I get this error:
TypeError: Cannot convert a BigInt value to a number
When I try to run my code outside of FCC I don’t get an Error and my code gives the expected results. Does anyone know why this happens/how I could fix the error?
Your code so far
function powerDigitSum(exponent) {
let string=(2n**BigInt(exponent)).toString()
return string.split("").reduce((sum,d)=>sum+Number(d),0)
}
powerDigitSum(1000);
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 8.1.0; SM-P580) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Safari/537.36
.
Challenge: Problem 16: Power digit sum
Link to the challenge: