Might be a typo in solution

Tell us what’s happening:
I can understand how a string can be an integer, but I don’t understand

  1. why do I have to use str here, when I can just use int? I’m required to return an integer, not a string.
  2. 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:

There “str” is a function parameter received from the convertToInteger() call which contains 10011.

When We parseInt(str,2); here 2 is the radix i.e. It specifies that the string we are passing is a binary string.

The parseInt method takes the string, takes the radix and then converts the binary string to a decimal number.

  1. str is a function argument, It’s just like the variable, you can name it anything…
    As we’re passing a string to the function, therefore it’s named str in this example

  2. parseInt function takes two arguments

    • String which contains an integer
    • base of embedded integer in the string

    therefore, 2 in the function argument refers that the string we’re passing is in binary format

So the function is about an argument that we’re passing through it, not about the answer/result. Gotcha. That’s a bit counterintuitive, but now I get it.