--- id: 587d7b7e367417b2b2512b23 title: Use the parseInt Function challengeType: 1 videoUrl: 'https://scrimba.com/c/cm83LSW' --- ## Description
The parseInt() function parses a string and returns an integer. Here's an example: var a = parseInt("007"); The above function converts the string "007" to an integer 7. If the first character in the string can't be converted into a number, then it returns NaN.
## Instructions
Use parseInt() in the convertToInteger function so it converts the input string str into an integer, and returns it.
## Tests
```yml tests: - text: convertToInteger should use the parseInt() function testString: assert(/parseInt/g.test(code), 'convertToInteger should use the parseInt() function'); - text: convertToInteger("56") should return a number testString: assert(typeof(convertToInteger("56")) === "number", 'convertToInteger("56") should return a number'); - text: convertToInteger("56") should return 56 testString: assert(convertToInteger("56") === 56, 'convertToInteger("56") should return 56'); - text: convertToInteger("77") should return 77 testString: assert(convertToInteger("77") === 77, 'convertToInteger("77") should return 77'); - text: convertToInteger("JamesBond") should return NaN testString: assert.isNaN(convertToInteger("JamesBond"), 'convertToInteger("JamesBond") should return NaN'); ```
## Challenge Seed
```js function convertToInteger(str) { } convertToInteger("56"); ```
## Solution
```js function convertToInteger(str) { return parseInt(str); } ```