Use the parseInt Function not passing

Tell us what’s happening:
I cant manage to get everything to pass, how do I nest them all in one?

convertToInteger should use the parseInt() function

Passed

convertToInteger("56") should return a number

Passed

convertToInteger("56") should return 56

convertToInteger("77") should return 77

convertToInteger("JamesBond") should return NaN

Your code so far


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

convertToInteger("56");

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 8.0.0; SM-T820) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.105 Safari/537.36.

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

Is there a reason why you’re passing a hard-coded “56” as argument in parseInt instead of the one given from the convertToInteger (i.e. str)?

I really don’t know why I was doing that but it passed once I changed it to str. Still confused but at least it past

You need to pass a variable as parameter so that whatever argument given when executing the function can be passed to the formula inside the function and be returned to where the function was initialized.

1 Like