Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.5 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7b7e367417b2b2512b22 Use the parseInt Function with a Radix 1 301182 use-the-parseint-function-with-a-radix

--description--

The parseInt() function parses a string and returns an integer. It takes a second argument for the radix, which specifies the base of the number in the string. The radix can be an integer between 2 and 36.

The function call looks like:

parseInt(string, radix);

And here's an example:

const 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.

--instructions--

Use parseInt() in the convertToInteger function so it converts a binary number to an integer and returns it.

--hints--

convertToInteger should use the parseInt() function

assert(/parseInt/g.test(__helpers.removeJSComments(code)));

convertToInteger("10011") should return a number

assert(typeof convertToInteger('10011') === 'number');

convertToInteger("10011") should return 19

assert(convertToInteger('10011') === 19);

convertToInteger("111001") should return 57

assert(convertToInteger('111001') === 57);

convertToInteger("JamesBond") should return NaN

assert.isNaN(convertToInteger('JamesBond'));

--seed--

--seed-contents--

function convertToInteger(str) {

}

convertToInteger("10011");

--solutions--

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