(Use the parseInt Function)

Tell us what’s happening:
I don’t have understand what i should do

Your code so far


function convertToInteger(str) {
  
}

convertToInteger("56");

Your browser information:

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

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

In the challenge example, do you understand that the following line converted the string “007” into the number 7 and assigned it to the variable a?

var a = parseInt("007");

If so, see if you can use the parseInt function on the argument passed into the function (str) and return the converted number.

Okay That I understand it the first is right now for others I don’t understand what to do

To which others are you referring?

convertToInteger(“56”) should return a number
convertToInteger(“56”) should return 56
convertToInteger(“77”) should return 77
convertToInteger(“JamesBond”) should return NaN

At that I don’t understand the code that I should do?
I try convertTolnteger(“56”)
and of all them same with the code above but it isn’t right

Read my first reply carefully.

Do you understand what the str parameter represents in the function definition?

Do you understand that parseInt is a function which will attempt to convert any string passed to it into Integer value?

Do you understand how to return a value in a function?

I understand of all this but i don’t understand the last one.

I don’t understand the last sentence

Review the following lesson to understand how to return a value from a function.

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return/

1 Like

I read it but again I don’t understand it sorry for tiredness but I don’t understand it

I believe it is easy but now I have many hours which I try to do it and mmy brain has got tired

You do not understand the lesson on how to return a value from a function? If so, which part of that lesson do you not understand?

I don’t understand it all I haven’t got a part of lesson!

You may need to start the Basic JavaScript section again and reset the code for each lesson. You seem to not understand some of the very first basics, so you will struggle very much through any later lessons until you can work through the first lessons without having to ask for help.

Well I believe she understood the whole var.

The problem in this section is that instead of var you should pay attention to this part here.

Use parseInt() in the convertToInteger function so it converts the input string str into an integer, and

returns it.

This changes the approach a bit. You shouldn’t be focusing on creating a var for the parseInt inside the function. But to return the parseInt inside the function. I got a bit confused there too and I understand what you meant.

Good Luck and Keep coding.

4 Likes

Thank you for your answer.

2 Likes

Thank you!!! I was confused about the wording too! Based on your explanation, I was able to get it. :raising_hand_woman:t5:‍♀

3 Likes