2.2 KiB
2.2 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7b7e367417b2b2512b22 | Use the parseInt Function with a Radix | 1 | Use a função parseInt com uma base |
Description
parseInt()
analisa uma string e retorna um inteiro. É preciso um segundo argumento para o radix, que especifica a base do número na string. O radix pode ser um inteiro entre 2 e 36. A chamada de função se parece com: parseInt(string, radix);
E aqui está um exemplo: var a = parseInt("11", 2);
A variável radix diz que "11" está no sistema binário, ou base 2. Este exemplo converte a string "11" em um inteiro 3. Instructions
parseInt()
na função convertToInteger
para converter um número binário em um inteiro e convertToInteger
-lo. Tests
tests:
- text: <code>convertToInteger</code> deve usar a função <code>parseInt()</code>
testString: 'assert(/parseInt/g.test(code), "<code>convertToInteger</code> should use the <code>parseInt()</code> function");'
- text: <code>convertToInteger("10011")</code> deve retornar um número
testString: 'assert(typeof(convertToInteger("10011")) === "number", "<code>convertToInteger("10011")</code> should return a number");'
- text: <code>convertToInteger("10011")</code> deve retornar 19
testString: 'assert(convertToInteger("10011") === 19, "<code>convertToInteger("10011")</code> should return 19");'
- text: <code>convertToInteger("111001")</code> deve retornar 57
testString: 'assert(convertToInteger("111001") === 57, "<code>convertToInteger("111001")</code> should return 57");'
- text: <code>convertToInteger("JamesBond")</code> deve retornar NaN
testString: 'assert.isNaN(convertToInteger("JamesBond"), "<code>convertToInteger("JamesBond")</code> should return NaN");'
Challenge Seed
function convertToInteger(str) {
}
convertToInteger("10011");
Solution
// solution required