# Use the parseInt Function need help to pass :)

Tell us what’s happening:

Your code so far

``````
function convertToInteger(str) {
return parseInt("56");
return parseInt("77");
return parseInt("JamesBond");
}

convertToInteger("56");
convertToInteger("77");
convertToInteger("JamesBond");
``````

User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36`.

I don’t think you’re quite getting what functions are for, or how to use them. A function takes an input and returns an output. If you don’t understand how they work, then you need to go back and review — functions are basic maths + are fundamental to writing code in programming languages (whether they’re called functions or methods or whatever).

In JS that means a function takes 0, 1 or more arguments, and can return a single value.

And with regards to arguments (eg, for your challenge the argument is called `str`):

``````function add2(x) {
return x + 2;
}
``````

So `x` is whatever number I give to the `add2` function — `add2(2)` is 4, `add2(167)` is 169. I don’t write the function like

``````function add2(x) {
return 2 + 2;
}
``````

That’s no use

1 Like

I don’t understand how to do it ``````function convertToInteger(str) {
return parseInt("56");
return parseInt("77");
return parseInt("JamesBond");
}
``````

So this just doesn’t make sense.

1. The point of this is that you have a function `convertToInteger` which takes any string and tries to convert it to an integer.
2. If programming worked in that you had to define every possible return value: for this basic function, for valid inputs you have every possible variation of every unicode character (basically every language + symbols, emojis etc) of any length.
3. Tests are just to check that your code works, the purpose of them is not for you to write code that only returns the values in the tests.
4. The function takes an argument, called `str`, that in your code you never use.
5. You can return one thing from a function.

To go back to functions in general:

``````function self(x) {
return x;
}
``````

This function takes an argument and returns that argument.

``````self(2) // returns 2
self('hi') // returns 'hi'
``````

The function is defined like this, you give the function a value and it returns a value:

``````function self(x) {
return x;
}
``````

It isn’t defined like this:

``````function self(x) {
return 2;
return 'Hi';
}
``````
1 Like

I was stuck on this same question but your response really helped put things into perspective and was able to figure out the answer. Thank you for taking out the time to write out stuff like that to help out us beginners. God bless you

1 Like