Use the parseInt Function need help

Use the parseInt Function need help


Tell us what’s happening:

Your code so far

function convertToInteger(str) {
  var a = parseInt("JamesBond");


Your browser information:

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

Link to the challenge:


I believe you can only parse numeric characters as an int

You need to use parseInt() on the string parameter of the function.


In this case, you can not parse a string like “JamesBond” to a number, this will just return a NaN which stands for (Not a Number).

Hopefully this helps.


You are to create a function that accepts a string representation of a number, uses parseInt to convert it to a number and then return that number.

For instance in the first test case you send “56” ( string with a 5 and a 6) and your function should return 56 (something that has a mathematical value).

So your function will need

  1. to use parseInt to make that string into a number
  2. a return statement to send that number back

Your problem seems to be more about understanding functions than understanding parseInt so I’ll include a similar example that does not totally spoil the answer to the challenge.

function convertToString(num) {
  var string = JSON.stringify(num);  // convert num to string
  return string;

console.log(56 + 100); // =156, number + number = number
console.log(numberToString(56) + 100); // =56100, string + number = string

My example is a function that accepts a number, uses JSON.stringify to convert it to a string and then returns that string. Opposite operation yet similar to the challenge as far as demonstrating how a function works.