Use the parseInt Fun

Tell us what’s happening:

Your code so far


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

convertToInteger("56");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36.

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

Hi @Himanshi, there are 2 main problems with the implementation:

  1. The parseInt function does not operate like that (you passed 2 parameters into it, rather than just the string)
  2. After fixing the parseInt function, you need to modify something else because otherwise you are only storing a value in a local variable (defined only inside the convertToInteger function)

Tip: the challenge text says:
Use parseInt() in the convertToInteger function so it converts the input string str into an integer, and returns it

Edit: passing a number as second parameter to the parseInt is valid, but only if such number is between 2 and 36 (both inclusive). Such number represent the base of the number you want to convert. More info https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

1 Like

thanks simonebogni…:slight_smile: