2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Use the parseInt Function
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Use the parseInt Function
|
|
|
|
|
|
|
|
---
|
|
|
|
## Problem Explanation
|
2019-01-15 14:54:07 -08:00
|
|
|
The ```parseInt()``` function will take any ```string``` parameter representing a number and return its integer value.
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Hints
|
|
|
|
|
|
|
|
### Hint 1
|
2019-01-15 14:54:07 -08:00
|
|
|
```parseInt()``` should be used inside your function and return whatever ```str``` is, assuming that ```str``` is a string representing some number.
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Solutions
|
|
|
|
|
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
|
|
|
|
2019-01-15 14:54:07 -08:00
|
|
|
```javascript
|
|
|
|
function convertToInteger(str) {
|
2019-07-24 00:59:27 -07:00
|
|
|
return parseInt(str);
|
2019-01-15 14:54:07 -08:00
|
|
|
}
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-01-15 14:54:07 -08:00
|
|
|
convertToInteger("56");
|
|
|
|
```
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
</details>
|