Use the parseInt Function, Basic JavaScript

Use the parseInt Function, Basic JavaScript
0

#1

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");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) 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


#2

Hi,

Your issue here is that you’re calling multiple return statements in a row. Since there are no conditional statements, convertToInteger will always return 56 and exit.

To solve this issue, your convertToInteger function should work for anything that is passed as str, not just the values that are tested in the challenge. Try making only one return statement where you pass str into the parseInt function.

Hope this helps.


#3
  1. After the function has returned something, it stops working.
  2. You’re not supposed to hardcode the values into parseInt method, instead parseInt the passed in argument (str).