Use the parseInt Function with a Radix. I didn't understand

Tell us what’s happening:

Your code so far


function convertToInteger(str,radix) {
 parseInt(str, radix);
 var a = parseInt(str, radix);
 return a;
}

convertToInteger("10011", 2);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix/

What you need to know?

I can’t solve the problem.

I’m stuck. I can’t decide?

Your code you show solves the problem.

The above is not necessary

function convertToInteger(str) {
    var radix = 2;
  var s = parseInt(str,radix);
  return s;
}

convertToInteger("10011", 2); 

check this out … solved

2 Likes

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.

2 Likes