ParseInt Java script help

Tell us what’s happening:
I’m not quite understanding why the 2 worked for the radix. I thought the radix could be any number between 2 and 36. I placed a 5 inside for the radix and my code was wrong. What am I not understanding?

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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36.

Challenge: Use the parseInt Function with a Radix

Link to the challenge:

the radix indicate the number system, so binary needs a 2

in general the radix can be any number in the range, but for this specific application there is one specific number needed

try console.log(convertToInteger("10011")) to print the value returned from the function on the console and change the radix, you will see the number change.

1 Like

Setting radix to 5 gives you a number system based on 0 to 4.

radix 2 (binary) -> radix 5 -> radix 10 (default)

0 -> 0 -> 0
1 -> 1 -> 1
10 -> 2 -> 2
11 -> 3 -> 3
110 -> 4 -> 4
111 -> 10 -> 5
1110 -> 11 -> 6
1111 -> 12 -> 7
11110 - > 13 -> 8
11111 -> 14 -> 9
111110 -> 20 -> 10

1 Like

Ok. I will print it and see what I get. Thanks for your help.