Give me suggestion to do further code:

Tell us what’s happening:

Your code so far


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

convertToInteger("56");

Your browser information:

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

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

The convertToInteger function receives an input (the argument str) and it should output (using return) the string as an integer.

You’re just setting the a variable the value of “56” converted to an integer. The function’s job is to convert any number, not just “56”.

Let me git you an example, the next function’s job is to receive a number in the input (the number argument) and return that number plus 1.

function addOne(number) {
  return number + 1;
}

Hopefully you can solve your problem.

no i don’t understand what are you saying

I think it may be best if you go back and start the curriculum javascript section over again. You can also read this link, it may clear things up for you:

https://www.w3schools.com/js/js_functions.asp

There’s no point in me giving you the answer directly because you will get stuck in future challenges. If you do want the answer anyway, just ask and I post here for you.

Good luck!

Tell us what’s happening:

Your code so far


function convertToInteger(str) {
  var a = parseInt("56","77","JamesBond");
  return 56 + 1,56;
if else{ return 77 + 1 , 77 ;} 
  return Nan ;
}




convertToInteger("56");

Your browser information:

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

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

All this challenge wants you to do is take the argument str and return it as an integer.

You don’t need any if / else statements, or to hard code any values like 56, 77, or James Bond.

You’ve been told in the instructions that parseInt converts a valid numerical string to an integer - that is the only tool you need for this challenge.

function convertToInteger(str) {
var a = parseInt(“JamesBond”);
return NaN ;
}

convertToInteger(“56”);

now can u plz solve this type of questions … so that i can pass this lesson … plz help … i am hanging on this being on several hours … i got tired on this question

That should do it:

function convertToInteger(str) {
  return parseInt(str);
}

convertToInteger("56");

Tell us what’s happening:

Your code so far


function convertToInteger(str) {
  return parseInt(str)
}

convertToInteger("10011");

Your browser information:

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

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

It is asked to convert the string in binary

What you are currently doing is converting it in Decimal .

Here is the example given in the explanation.

var a = parseInt("11", 2);

The radix variable says that “11” is in the binary system, or base 2. This example converts the string “11” to an integer 3.

And base 2 means binary.

function convertToInteger(str,rad) {
return parseInt(str,rad);

}

convertToInteger(“10011”);

The set up is a lot like the previous challenge where you had

return parseInt(str);

In this new challenge you have:
return parseInt(str, radix);

radix will be a number. radix means a base number, here is a video

Tell us what’s happening:

Your code so far


function convertToInteger(str,radix) {
    return parseInt(str,radix);
  
}

convertToInteger("10011",A0B);

Your browser information:

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

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

Why did you start a new thread for the exact same problem? It might be best practice to delete this thread and repost in the original thread. You can then say what you are not understanding

1 Like

Your radix should be an integer. 2, or 8, or 10 or something. What you have makes no sense.

yess i don’t understand plz kindly suggest what will i do

Well, you want an integer, as in a “normal” counting number, yes? What is the “base” of standard Western arithmetic? Binary is “base 2”, Octal is “base 8”, Hexadecimal is “base 16”, and Decimal is “base ??”

Yes but people were suggesting what you should do in your other thread. Now they cant respond because you opened a new thread. So try to explain what don’t you understand. and what have you tried. Also did you watch that video in the other thread or look up redax on google or what does base pair mean? @snowmonkey gave a good hint above.

Sorry, just logged in and saw this, didn’t realize there WAS another thread. My bad.

yes i have watched the videos …here it is suggesting that 0123456789 and after that 11 is equal to B and A is for 10 and c is for 12 etc…

while
in other section suggestion is saying that binary is for 2 and octa is for 8 and hexadecimal for 16