BigInt error in FCC editor?

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)


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:

First hint. You are correct that you need to cast a number to BigInt, but it is not the exponent that you need to convert.

I tried just converting the base to BigInt, but that didn’t work neither. I have a working example here:
or here:
It uses the same code and works.
I think the problem might somehow be caused by FCC

Ahh, I see. It might not like the 2n.

Since the exponent itself never gets into BigInt territory you don’t need to cast it as a BigInt. And the number 2 is certainly not a BigInt so you don’t need to use 2n. What you can do is cast the result of 2**exponent as a BigInt and then it will work in these tests. I’m not saying your way is wrong, as it definitely works. But in order to pass the FCC test you’ll need to do it my way.

1 Like

It works now. Thank you

For the record, there is currently an open issue regarding the way our compiler handles BigInt values: