Tell us what’s happening:
I can understand how a string can be an integer, but I don’t understand
- why do I have to use str here, when I can just use int? I’m required to return an integer, not a string.
- radix: why do I have to return base 2? I think it makes more sense to return base 10. I’m receiving a base 2 number and converting it to base 10. Why is the right answer “return base 2”, not “return base 10”?
Your code so far
function convertToInteger(str) {
return parseInt(str, 2);
}
convertToInteger("10011");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0
.
Challenge: Use the parseInt Function with a Radix
Link to the challenge: