Use the parseInt() Function with a Radix

Tell us what’s happening:
Trouble with parseInt Function with a Radix

Your code so far


function convertToInteger(x, base) {
   var a = parseInt(x, base);
   return a;
  
}

 convertToInteger("10011", 2);
 

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15.

using console.log I get 19 which is the correct answer. When I call the function, I don’t get 19. Why?

Hi webguypro,

use this code:
<removed>

The issue is that the tests only give one argument, so your function is not getting the radix (the base). You will need to hardcode that one, or use default parameters

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Thank you for understanding.

1 Like
1 Like

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

If you want to compare your solution to others, use the Get a hint button on the challenge and there are alternative solutions you can compare yours to. Also, you can probably search older posts using the forum search feature or google the challenge name and find more there.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Thank you for understanding.

I have same issue, can u post code again coz its removed

Instead why don’t you try to use he Ask for Help button to ask for help based on your solution? Wouldn’t be better if you arrive to the solution on your own, even with all the help you need?

1 Like