Use the parseInt Function with a Radix prb

Use the parseInt Function with a Radix prb
0

#1

Tell us what’s happening:
where I can use the radix element ? because in the function they only mention the str.

Your code so far


function convertToInteger(str) { 
    return parseInt(str);
  
}

convertToInteger("10011");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 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


#2

@sojib-bd,

in the lesson they are referring to the radix base that can be an optional second argument to the parseInt method.


#3

what else should i write in the code?


#4

I have most of it correct but cant seem to return 19 and 56 i need help.

This is my code so far:

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

    
}

convertToInteger("10011");

#5

@Duwayne16,

I would suggest you try debugging your code, with console.logs, and see where your code falls short. After that, if you still can’t figure out the issue, post again and we will try to help.


#6

Hey man still not getting it.


#7

What did you try? Did you add console.log statements? What did you see? Give us some information.


#8

Yes i console.log but done it several times to see my mistake but helped a lot thanks.


#9

Awesome that you solved the problem. Care to elaborate so you can help people who will have the same issue?


#10

Yes please, @Duwayne16, could you elaborate?

I am stuck on this challenge too, actually when I try to use the convertToInteger to get the result as 57, with 111001, it does work on Chrome’s console, but when I try on FCC it won’t…

Any tips please?