# freeCodeCamp Challenge Guide: Use the parseInt Function with a Radix

**URL:** <https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-use-the-parseint-function-with-a-radix/301182>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [August 3, 2019, 5:46am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-use-the-parseint-function-with-a-radix/301182 "2019-08-03T05:46:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [August 3, 2019, 5:46am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-use-the-parseint-function-with-a-radix/301182/1 "2019-08-03T05:46:49Z")

</div>

# [Use the parseInt Function with a Radix](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix)

* * *

## Hints

### Hint 1

If you use a variable to assign the result of `parseInt(str)` to it, remember to return that variable.  
Otherwise you can just use a `return` statement for your function.

### Hint 2

In this exercise you need to “convert” a binary number into a decimal number using the `radix` parameter in order to specify the base on which the input number is represented on.

* * *

## Solutions

> **Solution 1 (Click to Show/Hide)**
>
> ```javascript
> function convertToInteger(str) {
> return parseInt(str, 2);
> }
> convertToInteger("10011");
> 
> ```
> 
> #### Code Explanation
> 
> - The function takes `str` and returns an integer instead of a string but “understanding” its a binary number instead of a decimal one thanks to the `radix` parameter (2).
> 
> #### Relevant Links
> 
> - [“parseInt()” - _MDN JavaScript reference_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
> - [“Radix” - _Wikipedia_](https://en.wikipedia.org/wiki/Radix)

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 8, 2025, 3:59pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-use-the-parseint-function-with-a-radix/301182/2 "2025-01-08T15:59:15Z")

</div>


